PR#4202: RawHeader: fix store offsets when duplicate tags are present

Merges #4202
https://pagure.io/koji/pull-request/4202

Fixes: #4203
https://pagure.io/koji/issue/4203
RawHeader miscalculates offsets when there are duplicate tags
This commit is contained in:
Tomas Kopecek 2025-01-07 12:49:06 +01:00
commit 177ba3510f
2 changed files with 14 additions and 19 deletions

View file

@ -690,7 +690,8 @@ class RawHeader(object):
dl = multibyte(data[4:8])
# read the index (starts at offset 16)
index = {}
index = []
tag_index = {}
for i in range(il):
entry = []
for j in range(4):
@ -699,21 +700,22 @@ class RawHeader(object):
entry.append(multibyte(data))
# print("Tag: %d, Type: %d, Offset: %x, Count: %d" % tuple(entry))
index[entry[0]] = entry
index.append(entry)
tag_index[entry[0]] = entry
# in case of duplicate tags, last one wins
self.datalen = dl
self.index = index
self._store = 16 + il * 16
self._index = index # list
self.index = tag_index # dict
def dump(self, sig=None):
print("HEADER DUMP:")
# calculate start of store
il = len(self.index)
store = 16 + il * 16
# print("start is: %d" % start)
# print("index length: %d" % il)
print("Store at offset %d (%0x)" % (store, store))
store = self._store
print("Store at offset %d (0x%0x)" % (store, store))
# sort entries by offset, dtype
# also rearrange: tag, dtype, offset, count -> offset, dtype, tag, count
order = sorted([(x[2], x[1], x[0], x[3]) for x in six.itervalues(self.index)])
order = sorted([(x[2], x[1], x[0], x[3]) for x in self._index])
# map some rpmtag codes
tags = {}
if rpm:
@ -869,9 +871,7 @@ class RawHeader(object):
def _getitem(self, dtype, offset, count, decode=None):
if decode is None:
decode = self.decode
# calculate start of store
il = len(self.index)
store = 16 + il * 16
store = self._store
pos = store + offset
if dtype >= 2 and dtype <= 5:
values = []

View file

@ -8185,12 +8185,7 @@ def add_rpm_sig(an_rpm, sighdr):
if not sigkey:
sigkey = rawhdr.get(koji.RPM_SIGTAG_RSA)
else:
# In older rpms, this field in the signature header does not actually match
# sigmd5 (I think rpmlib pulls it from SIGTAG_GPG). Anyway, this
# sanity check fails incorrectly for those rpms, so we fall back to
# a somewhat more expensive check.
# ALSO, for these older rpms, the layout of SIGTAG_GPG is different too, so
# we need to pull that differently as well
# Double check using rpm in case we have somehow misread
rpm_path = "%s/%s" % (builddir, koji.pathinfo.rpm(rinfo))
sigmd5, sigkey = _scan_sighdr(sighdr, rpm_path)
sigmd5 = koji.hex_string(sigmd5)