Message405760
I was looking at `zipfile._strip_extra` trying to figure out how it works. It doesn't. It skips extra headers after the last one that matches. That's what causes this issue.
Here's a fixed version:
def _strip_extra(extra, xids):
# Remove Extra Fields with specified IDs.
unpack = _EXTRA_FIELD_STRUCT.unpack
modified = False
buffer = []
start = i = 0
while i + 4 <= len(extra):
xid, xlen = unpack(extra[i : i + 4])
j = i + 4 + xlen
if xid in xids:
if i != start:
buffer.append(extra[start : i])
start = j
modified = True
i = j
if i != start:
buffer.append(extra[start : i])
if not modified:
return extra
return b''.join(buffer)
Or this one, easier to understand:
def _strip_extra(extra, xids):
# Remove Extra Fields with specified IDs.
unpack = _EXTRA_FIELD_STRUCT.unpack
modified = False
buffer = []
i = 0
while i + 4 <= len(extra):
xid, xlen = unpack(extra[i : i + 4])
j = i + 4 + xlen
if xid in xids:
modified = True
else:
buffer.append(extra[i : j])
i = j
if not modified:
return extra
return b''.join(buffer)
Not sure which one is better. |
|
Date |
User |
Action |
Args |
2021-11-05 00:04:59 | anadius | set | recipients:
+ anadius, shaanbhaya |
2021-11-05 00:04:58 | anadius | set | messageid: <1636070698.99.0.861558169316.issue44067@roundup.psfhosted.org> |
2021-11-05 00:04:58 | anadius | link | issue44067 messages |
2021-11-05 00:04:58 | anadius | create | |
|