Skip to content

problem_report: enforce some keys to always have str values in load()#588

Merged
bdrung merged 1 commit intocanonical:mainfrom
bdrung:fix-2146806
Apr 24, 2026
Merged

problem_report: enforce some keys to always have str values in load()#588
bdrung merged 1 commit intocanonical:mainfrom
bdrung:fix-2146806

Conversation

@bdrung
Copy link
Copy Markdown
Member

@bdrung bdrung commented Apr 21, 2026

plasmashell crashed on the system, and when Apport tried to upload the problem report, whoopsie-upload-all crashed:

INFO:root:Collecting info for /var/crash/_usr_bin_plasmashell.1000.crash...
ERROR: hook /usr/share/apport/general-hooks/generic.py crashed:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport/report.py", line 314, in _run_hook
    symb["add_info"](report, ui)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/share/apport/general-hooks/generic.py", line 70, in add_info
    for lib in re.finditer(r"\s(/[^ ]+\.so[.0-9]*)$", report["ProcMaps"], re.M):
               ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/re/__init__.py", line 285, in finditer
    return _compile(pattern, flags).finditer(string)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
  File "/usr/share/apport/whoopsie-upload-all", line 246, in <module>
    main()
    ~~~~^^
  File "/usr/share/apport/whoopsie-upload-all", line 228, in main
    stamps = collect_info()
  File "/usr/share/apport/whoopsie-upload-all", line 162, in collect_info
    res = process_report(r)
  File "/usr/share/apport/whoopsie-upload-all", line 112, in process_report
    r.add_gdb_info()
    ~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1057, in add_gdb_info
    addr_signature = self.crash_signature_addresses()
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1797, in crash_signature_addresses
    if self["ProcMaps"].startswith("Error: "):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

The ProcMaps field in the crash report has following last lines:

 7f8e5d61b000-7f8e5d61e000 r-xp 00002000 fc:00 19081540                   /usr/lib/x86_64-linux-gnu/qt6/plugins/kf6/packagestructure/plasma_wallpaper.so
 7f8e5d61e000-7f8e5d61f000 r--p 00005000 fc:00 19081540                   /usr/lib/x86_64-linux-gnu/qt6/plugins/kf6/packagestructure/plasma_wallpaper.so
 7f8e5d61f000-7f8e5d620000 r--p 00005000 fc:00 190815U\0\0

So string value for ProcMaps seems to be truncated. whoopsie-upload-all opens the crash file and keeps the value as bytes because it contains null characters at the end.

The value for ProcMaps should always be a string. There are other fields that are expected to be string as well.

Enforce decoding those fields when reading the crash report and prevent setting those keys to non-string values. This should result in more consistent ProblemReport object instances. This can be accompanied by type hints in a future commit.

Bug: https://launchpad.net/bugs/2146806

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.52%. Comparing base (19cf32f) to head (3588162).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #588   +/-   ##
=======================================
  Coverage   84.51%   84.52%           
=======================================
  Files         104      104           
  Lines       20988    21000   +12     
  Branches     3218     3219    +1     
=======================================
+ Hits        17739    17751   +12     
  Misses       2808     2808           
  Partials      441      441           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@Hyask Hyask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in overall, just one question.

Comment thread problem_report.py
@bdrung
Copy link
Copy Markdown
Member Author

bdrung commented Apr 24, 2026

Just rebased on master.

@bdrung
Copy link
Copy Markdown
Member Author

bdrung commented Apr 24, 2026

Noticed this problem with this patch set:

divide-by-zero
PYTHONPATH=$(pwd) APPORT_LAUNCHPAD_INSTANCE=qastaging bin/apport-cli /var/crash/_usr_bin_divide-by-zero.1000.crash
$ PYTHONPATH=$(pwd) APPORT_LAUNCHPAD_INSTANCE=qastaging bin/apport-retrace --auth ~/.cache/apport/launchpad.credentials -S system 2143181
ERROR: Broken report: value for key Dependencies must be a string, closing as invalid

So more changes are needed.

plasmashell crashed on the system, and when Apport tried to upload the
problem report, whoopsie-upload-all crashed:

```
INFO:root:Collecting info for /var/crash/_usr_bin_plasmashell.1000.crash...
ERROR: hook /usr/share/apport/general-hooks/generic.py crashed:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport/report.py", line 314, in _run_hook
    symb["add_info"](report, ui)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/share/apport/general-hooks/generic.py", line 70, in add_info
    for lib in re.finditer(r"\s(/[^ ]+\.so[.0-9]*)$", report["ProcMaps"], re.M):
               ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/re/__init__.py", line 285, in finditer
    return _compile(pattern, flags).finditer(string)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
  File "/usr/share/apport/whoopsie-upload-all", line 246, in <module>
    main()
    ~~~~^^
  File "/usr/share/apport/whoopsie-upload-all", line 228, in main
    stamps = collect_info()
  File "/usr/share/apport/whoopsie-upload-all", line 162, in collect_info
    res = process_report(r)
  File "/usr/share/apport/whoopsie-upload-all", line 112, in process_report
    r.add_gdb_info()
    ~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1057, in add_gdb_info
    addr_signature = self.crash_signature_addresses()
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1797, in crash_signature_addresses
    if self["ProcMaps"].startswith("Error: "):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
```

The `ProcMaps` field in the crash report has following last lines:

```
 7f8e5d61b000-7f8e5d61e000 r-xp 00002000 fc:00 19081540                   /usr/lib/x86_64-linux-gnu/qt6/plugins/kf6/packagestructure/plasma_wallpaper.so
 7f8e5d61e000-7f8e5d61f000 r--p 00005000 fc:00 19081540                   /usr/lib/x86_64-linux-gnu/qt6/plugins/kf6/packagestructure/plasma_wallpaper.so
 7f8e5d61f000-7f8e5d620000 r--p 00005000 fc:00 190815U\0\0
```

So string value for `ProcMaps` seems to be truncated.
whoopsie-upload-all opens the crash file and keeps the value as `bytes`
because it contains null characters at the end.

The value for `ProcMaps` should always be a string. There are other
fields that are expected to be string as well.

Enforce decoding those fields when reading the crash report. This should
result in more consistent `ProblemReport` object instances. This can be
accompanied by type hints in a future commit.

Bug: https://launchpad.net/bugs/2146806
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
@bdrung
Copy link
Copy Markdown
Member Author

bdrung commented Apr 24, 2026

Let's split this PR into two. I rebased this PR on main and only kept "problem_report: enforce some keys to always have str values in load()".

The other two commits will be submitted in a follow-up PR once I addressed the apport-retrace issue mentioned above.

@bdrung bdrung changed the title problem_report: enforce some keys to always have str values problem_report: enforce some keys to always have str values in load() Apr 24, 2026
@bdrung bdrung merged commit 3588162 into canonical:main Apr 24, 2026
19 checks passed
@bdrung bdrung deleted the fix-2146806 branch April 24, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants