Landscape 23.03, can't handle binary script attachments

Bug #2070049 reported by Nikita Koltsov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Landscape Server
Fix Released
Medium
Kevin Nasto
23.03
Fix Released
Medium
Kevin Nasto

Bug Description

When attachment has binary files in it each time I'm trying to read this attachment also by trying to download it or by trying to copy script, I could see the following error from this message.

Replicate the issue is quite simple.
On Landscape 23.03:
1. Create script
2. Attach any binary file to the script for example archive
3. Open saved attachment and click on the attached file

Stack trace is leading to problematic decode() call, I checked the latest package and the issue is still there

./api.log:Jun 21 12:13:58 api-2 CRIT
Traceback (most recent call last):

  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 857, in _runCallbacks

    current.result = callback( # type: ignore[misc]
  File "/opt/canonical/landscape/canonical/landscape/api/methods.py", line 211, in _handle_errors
    raise UndeclaredException(self.schema, failure)
canonical.landscape.api.methods.UndeclaredException: Error type UnicodeDecodeError was raised from schema CopyScript which only declares ['UnknownScript', 'UnknownAccessGroup', 'DuplicateScript', 'Unauthorised']. Full traceback:
 Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/twisted/_threads/_threadworker.py", line 47, in work
    task()
  File "/usr/lib/python3/dist-packages/twisted/_threads/_team.py", line 182, in doWork
    task()
--- <exception caught here> ---
  File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 244, in inContext
    result = inContext.theWork() # type: ignore[attr-defined]
  File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 260, in <lambda>
    inContext.theWork = lambda: context.call( # type: ignore[attr-defined]
  File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 117, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 82, in callWithContext
    return func(*args, **kw)
  File "/usr/lib/python3/dist-packages/storm/twisted/transact.py", line 78, in _wrap
    result = function(*args, **kwargs)
  File "/opt/canonical/landscape/canonical/landscape/api/methods.py", line 151, in _transaction
    return self.query(context, call)
  File "/opt/canonical/landscape/canonical/landscape/api/scripts.py", line 633, in query
    script = context.copy_script(
  File "/opt/canonical/landscape/canonical/landscape/model/script/management.py", line 171, in copy_script
    [
  File "/opt/canonical/landscape/canonical/landscape/model/script/management.py", line 172, in <listcomp>
    (attachment.filename, attachment.get_data())
  File "/opt/canonical/landscape/canonical/landscape/model/script/script.py", line 437, in get_data
    data = self._read(fd)
  File "/opt/canonical/landscape/canonical/landscape/model/script/script.py", line 486, in _read
    return result.get_one()[0].tobytes().decode()
builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 14: invalid start byte

information type: Proprietary → Public
Changed in landscape:
assignee: nobody → Kevin Nasto (silverdrake11)
importance: Undecided → Medium
status: New → Confirmed
no longer affects: landscape/beta
no longer affects: landscape/24.04
no longer affects: landscape/24.10
Changed in landscape:
milestone: 24.10-beta.2 → none
Changed in landscape:
milestone: none → 23.03+18.3
Changed in landscape:
milestone: 23.03+18.3 → none
Changed in landscape:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.