Skip to content

Commit 5fb6c91

Browse files
committed
fix(apt): fix compression when python-apt is available
When python-apt is available, and thus apt_pkg, the iter_paragraphs method only accepts filehandles in python-debian 0.1.49. Contrary to what the docs state, passing a filehandle to an encrypted file causes a segmentation fault. Thus we need to treat it differently. When dealing with compressed files we now decompress the file and never us python-apt. For python debian >= 1.0.0 this behavior is fixed, and the method also accepts filenames. Debian bookworm still uses 0.1.49, so we have to have this workaround for now. Fixes: 2d070dc feat(apt): allow reading of compressed apt-cache files Signed-off-by: Christoph Steiger <[email protected]>
1 parent 80be4d7 commit 5fb6c91

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/debsbom/apt/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _parse_sources(
125125
logger.debug(f"Parsing apt cache source packages: {sources_file}")
126126
# TODO: in python-debian >= 1.0.0 it is possible to directly
127127
# pass the filename of a compressed file when using apt_pkg
128-
sources_raw = Packages.iter_paragraphs(content, use_apt_pkg=HAS_PYTHON_APT)
128+
sources_raw = Packages.iter_paragraphs(content, use_apt_pkg=False)
129129
for s in Repository._make_srcpkgs(sources_raw, srcpkg_filter):
130130
yield s
131131
except (FileNotFoundError, IndexError, RuntimeError):
@@ -148,7 +148,7 @@ def _parse_packages(
148148
content = stream_compressed_file(compressed_variant)
149149
# TODO: in python-debian >= 1.0.0 it is possible to directly
150150
# pass the filename of a compressed file when using apt_pkg
151-
packages_raw = Packages.iter_paragraphs(content, use_apt_pkg=HAS_PYTHON_APT)
151+
packages_raw = Packages.iter_paragraphs(content, use_apt_pkg=False)
152152
logger.debug(f"Parsing apt cache binary packages: {packages_file}")
153153
for s in Repository._make_binpkgs(packages_raw, binpkg_filter):
154154
yield s

0 commit comments

Comments
 (0)