From f3786d8d3ebb415df0f3b433b7fd98be126732fb Mon Sep 17 00:00:00 2001 From: Carl-Friedrich Braun Date: Tue, 11 Nov 2025 09:59:20 +0100 Subject: [PATCH] fix: support uncompressed control.tar archives --- pydpkg/dpkg.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pydpkg/dpkg.py b/pydpkg/dpkg.py index 0d7b0d2..fbc3231 100644 --- a/pydpkg/dpkg.py +++ b/pydpkg/dpkg.py @@ -271,7 +271,7 @@ def _extract_message(self, ctar: tarfile.TarFile) -> Message[str, str]: self._log.debug("got control message: %s", message) return message - def _read_archive(self, dpkg_archive: Archive) -> tuple[ArchiveFileData, Literal["gz", "xz", "zst"]]: + def _read_archive(self, dpkg_archive: Archive) -> tuple[ArchiveFileData, Literal["gz", "xz", "zst", "none"]]: """Search an opened archive for a compressed control file and return it plus the compression""" dpkg_archive.read_all_headers() @@ -287,6 +287,10 @@ def _read_archive(self, dpkg_archive: Archive) -> tuple[ArchiveFileData, Literal control_archive = dpkg_archive.archived_files[b"control.tar.zst"] return control_archive, "zst" + if b"control.tar" in dpkg_archive.archived_files: + control_archive = dpkg_archive.archived_files[b"control.tar"] + return control_archive, "none" + raise DpkgMissingControlGzipFile("Corrupt dpkg file: no control.tar.gz/xz/zst file in ar archive.") def _extract_message_from_tar(self, fd: SupportsRead[bytes], archive_name: str = "undefined") -> Message[str, str]: @@ -298,7 +302,7 @@ def _extract_message_from_tar(self, fd: SupportsRead[bytes], archive_name: str = return message def _extract_message_from_archive( - self, control_archive: IO[bytes], control_archive_type: Literal["gz", "xz", "zst"] + self, control_archive: IO[bytes], control_archive_type: Literal["gz", "xz", "zst", "none"] ) -> Message[str, str]: """Extract the control file from a compressed archive fileobj""" if control_archive_type == "gz": @@ -314,6 +318,9 @@ def _extract_message_from_archive( with zst.stream_reader(control_archive) as reader: return self._extract_message_from_tar(reader, "zst") + if control_archive_type == "none": + return self._extract_message_from_tar(control_archive, "none") + raise DpkgError(f"Unknown control archive type: {control_archive_type}") def _process_dpkg_file(self, filename: str) -> Message[str, str]: