Skip to content

Commit

Permalink
Handle empty RPMs during extracting
Browse files Browse the repository at this point in the history
If an RPM does not contain any files, we also do not need to extract any
file signatures.

Signed-off-by: Patrick Uiterwijk <[email protected]>
  • Loading branch information
puiterwijk committed Sep 27, 2021
1 parent bf35c8f commit 1c4d514
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions rpm_head_signing/extract_rpm_with_filesigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ def _extract_rpm(rpm_path, output_path):
RPMSIGTAG_RSAHEADER = 268


class NonImaSignedPackage(ValueError):
pass


# Koji doesn't support type 8 (string array) for returning
def _get_header_type_8(raw_hdr, tag):
entry = raw_hdr.index.get(RPMSIGTAG_FILESIGNATURES)
if entry is None:
raise Exception("No file signatures found")
raise NonImaSignedPackage("No file signatures found")
(dtype, offset, count) = entry[1:]
# This is basically RawHeader._getitem, but then for only type 8
il = len(raw_hdr.index)
Expand All @@ -84,17 +88,22 @@ def _get_header_type_8(raw_hdr, tag):
def _extract_filesigs(rpm_path):
sighdr = rip_rpm_sighdr(rpm_path)
sighdr = RawHeader(sighdr)
filesigs = _get_header_type_8(sighdr, RPMSIGTAG_FILESIGNATURES)

if not filesigs:
return None

rpm_hdr = get_rpm_header(rpm_path)
fileflags = rpm_hdr[rpm.RPMTAG_FILEFLAGS]
diridxs = rpm_hdr[rpm.RPMTAG_DIRINDEXES]
dirnames = rpm_hdr[rpm.RPMTAG_DIRNAMES]
basenames = rpm_hdr[rpm.RPMTAG_BASENAMES]

if len(basenames) == 0:
logging.debug("Empty RPM encountered")
return {}

filesigs = _get_header_type_8(sighdr, RPMSIGTAG_FILESIGNATURES)

if not filesigs:
return None

if len(basenames) != len(filesigs):
raise Exception(
"Invalid number of file signatures (%d) for basenames (%d)"
Expand Down

0 comments on commit 1c4d514

Please sign in to comment.