aptsources deb822 Section constructor fails on valid .sources file

Bug #2025965 reported by Mike Vastola
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-apt (Ubuntu)
New
Undecided
Unassigned

Bug Description

When attempting to parse (what I believe is) a perfectly valid deb822-formated `.sources` file, the library's `_deb822.Section` constructor parses my file incorrectly, resulting in an exception being thrown.

At a low level, the error is `ValueError: Unable to parse section data` and is thrown in the `_deb822.Section` constructor, located at line 41 of `aptsources/_deb822.py`. The error was caused by the evaluation of `apt_pkg.TagSection(trimmed_section)` on that line with `trimmed_section` being an empty string.

At a high level, based on a cursory debug, it seems the parser incorrectly considers the first three lines of my `.sources` file -- which are, in fact, comments -- to be a stanza, and is trying to instantiate an object for them, despite them having no non-ignored content.

Notably, -- supporting my conclusion -- this issue disappears entirely if I remove the first blank line in the file (located after those comments and before the first stanza).

I am attaching my .sources file for reference.

Notes:
- FWIW, I don't use this library directly; the code at issue gets invoked by the `command-not-found` package/bash handler. (The warnings therefore show up every time I mistype a command.) In any case, I traced the issue down to this package.
- My python3-apt package is version 2.5.3ubuntu1 from lunar/main.
- This error began for me upon an upgrade from jammy to lunar. This sources file was unchanged during the upgrade (except for renaming `jammy` to `lunar`, and changing `Enabled` to `no` in the `partner` stanza).

Revision history for this message
Mike Vastola (michael-vastola) wrote :
Revision history for this message
Mike Vastola (michael-vastola) wrote :

Also, if it helps, here's a minimal example python file, triggering the error (requires attached `00ubuntu.sources` to be in cwd)

no longer affects: command-not-found (Ubuntu)
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.