anadius <anad...@gmail.com> added the comment:
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. ---------- nosy: +anadius _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44067> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com