# -*- coding: utf-8 -*- """xlsx(zip) 读写的兼容层。 背景:台账被 WPS 保存后,透视缓存的 `pivotCacheRecords*.xml` 会写成 「local header 里 size=0xFFFFFFFF + ZIP64 extra 带真实大小、central directory 却缺 ZIP64 extra」。 Python 3.11 的 zipfile 从 central 取到 0xFFFFFFFF,把条目当成 4GB, `ZipFile.open()` 直接抛 `BadZipFile: Overlapped entries ... (possible zip bomb)`。 这里在打开后把这类 ZipInfo 的 size 修成真实值(解析 local header 的 ZIP64 extra, 取不到就用下一条目偏移反推),只改内存对象、不动文件;之后 `zf.open(info)` 可正常读。 """ import struct import zipfile def _local_sizes(fp, info): """从 local file header 的 ZIP64 extra 取 (usize, csize),取不到返回 (None, None)。""" fp.seek(info.header_offset) hdr = fp.read(30) if len(hdr) < 30 or hdr[:4] != b'PK\x03\x04': return None, None nlen, elen = struct.unpack('= 16: usize, csize = struct.unpack('= 8: usize = struct.unpack('