Skip to content

problem_report: validate key names in ProblemReport.load - #646

Open
bdrung wants to merge 2 commits into
canonical:mainfrom
bdrung:fix-key
Open

problem_report: validate key names in ProblemReport.load#646
bdrung wants to merge 2 commits into
canonical:mainfrom
bdrung:fix-key

Conversation

@bdrung

@bdrung bdrung commented Aug 18, 2026

Copy link
Copy Markdown
Member

Apport report files consist of key/value pairs based on the standard RFC822 format, except that Apport uses case sensitive keys. Key names must only contain numbers, letters, '.', '_', and '-'. This is validated in ProblemReport.__setitem__, but not when loading a report in ProblemReport.load.

So use ProblemReport.__setitem__ in ProblemReport.load as well.

This PR depends on #580 landing first.

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

bdrung added 2 commits August 18, 2026 19:30
The documentation for `ProblemReport.load()` says:

> If binary is False, binary data is not loaded; the dictionary key is
> created, but its value will be an empty string.

Commit 64820a0 ("apport-unpack: Fix ValueError: ['separator'] has
no binary content") changed this behavior to fix a crash in
apport-unpack.

Setting non-loaded values to `None` will make type hints more
complicated and less useful. Values in the problem report should not be
allowed to be `None`.

Instead of adding dictionary keys with a special value for not loaded
keys, just let `load()` return the keys that were skipped. This reduces
guess work and make the code more robust.

Remove `ProblemReport.has_removed_fields()` since that information is
lost and this function was only used in Apport tests.
Apport report files consist of key/value pairs based on the standard
RFC822 format, except that Apport uses case sensitive keys. Key names
must only contain numbers, letters, '.', '_', and '-'. This is validated
in `ProblemReport.__setitem__`, but not when loading a report in
`ProblemReport.load`.

So use `ProblemReport.__setitem__` in `ProblemReport.load` as well.

Bug: https://launchpad.net/bugs/2161697
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.48%. Comparing base (7ce5916) to head (66b9a3f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #646      +/-   ##
==========================================
- Coverage   84.48%   84.48%   -0.01%     
==========================================
  Files         106      106              
  Lines       21044    21036       -8     
  Branches     3192     3190       -2     
==========================================
- Hits        17780    17772       -8     
  Misses       2790     2790              
  Partials      474      474              

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant