Repository navigation
fix(desktop): read a Zip64 end record that carries an extensible data sector - #10618
XiaoBinGan wants to merge 1 commit into
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; the previous boundary issue is fixed. SummaryReads Zip64 end records with an extensible data sector in desktop inspection and exported Python readers.
Reviews (7) · Last reviewed commit: "fix(desktop): bound the Zip64 search on ..." · Reviewed by Greptile |
|
Correct, and a real gap I introduced: the inspection reader could read the record while the exported Python reader still read exactly 56 bytes before the locator, so a document readable during inspection became unreadable in the exported environment.
While writing it I also found the locator layout mattered: signature (4), the disk it names (4), the record's offset at One gap I must record: no Python interpreter is installed on this host. |
|
Correct. The search sought and read for every byte, so an unusable declared offset cost about a million reads through the exported reader's disk-backed handle. The bytes before the locator are now read once and the search indexes into them, and |
|
Correct. The declared offset is now read where it points, in one fixed-size read, and the search window behind the locator is what I should also record the honest limit of my verification here: there is no Python interpreter on this host, so the exported reader is checked statically — module indentation and bracket balance, plus a line-by-line comparison with the inspection read, whose 8 case matrix (prepended × extensible) passes. The reader itself has not been executed. |
614ba18 to
edff236
Compare
|
Right, and the boundary was off by exactly the record's own size.
- locator - at <= ZIP64_EXTENSIBLE_LIMIT
+ locator - at - ZIP64_END_BYTES <= ZIP64_EXTENSIBLE_LIMITMeasured on a prepended archive (16 leading bytes) against sector sizes around the bound:
So 56 bytes of reach were lost, exactly as you described, and prepended data is what forces the Boundary case added in I have not verified the Python comparison directly — there is no Python interpreter on this host — so
|
… sector APPNOTE 4.3.14 puts a variable-size extensible data sector after the Zip64 end record's 56 fixed bytes, and 4.3.15 has its locator declare that record's offset. The reader assumed the record was always the 56 bytes immediately before the locator, so an archive written with a sector either lost its Zip64 record entirely or read the classic fields the record exists to override. Measured on a 1 MiB sector, the reader's reach went from "no record" to "record found" for every sector up to the `1 << 20` bound, and the declared offset is taken first when it points at a record whose own length ends exactly at the locator — so an archive embedded after leading bytes, where the declared archive offset cannot be used directly, is still found. `appExportPythonZip.ts` had its own copy of the same assumption in the exported reader; it now reads through the same scan. Three reads that were spelled out are now `u32At` / `u64At`, which took this file from 14 counted raw reads to 12 and let the baseline shrink. **Verification.** `src/domain/desktop/zipDirectory.test.ts` — 3 passing, covering a record with a sector, one whose sector is exactly the bound, and one beyond it. `tsc --noEmit` 0 errors. `architecture-guards` passed across 2 818 source files. `npm run lint` 0 errors. The branch was 700 commits behind and `scripts/verify/architecture-guard-baselines.json` was split into per-guard files under `scripts/verify/baselines/` while it sat, so it is rebased: the one line this PR lowered now lives in `baselines/raw-buffer-read.json`.
b7e920d to
8a60ade
Compare
|
The host and generated Python readers now follow the declared Zip64 end-record span, including the extensible sector, in #12157. Closing this superseded implementation. |
Summary
directoryEndlocated the Zip64 end-of-central-directory record by subtracting its fixed 56 bytes from the locator. APPNOTE 4.3.14 lets that record end with a variable-size extensible data sector, so a conforming archive whose record carries one was refused asnot a readable zip archivewith no entries listed.Measured
A one-member Zip64 archive whose record ends with N extensible bytes, on this host:
unzip -la.txta.txta.txta.txtInfo-ZIP
unziplists the member of every one of those archives, so the refusal is an accept/reject flip against a reference reader, not a stricter reading of the format.Approach
4.3.15 has the locator declare the record's offset, so the declared offset is read first. A record can only end where its locator begins, and only the record's own length field says where it begins — so that length must land exactly on the locator. That check is what distinguishes the real record from a coincidental signature, and it keeps the refusal when a declared offset points at something else.
When the declared offset does not land there, the fixed 56 bytes before the locator are read first, as
zipfileandzip.jsdo, and then the bytes behind them are walked for the record's real start, bounded byZIP64_EXTENSIBLE_LIMIT.A declared archive offset cannot account for data prepended to the archive, so the walk also makes that case work:
Evidence
src/domain/desktop/zipDirectory.test.ts— new file, 2 cases covering both tables above. Reverting the source fails both (2 failed), and no test previously calledscanZipDirectoryat all.tests/boundary/providers/desktopZipPython.test.ts:388,405) build their archives withwithZip64End, which always writes a 44-byte body hard against its locator — the shape that cannot see this defect.src/domain/desktop,src/domain/apkSignature,src/domain/zipEndOfCentralDirectory.test.ts— 1012 passing. The singleappWithheldfailure reproduces onmainon this Windows host.npx tsc --noEmit -p .— 0 errors.npm run lint— 0 errors.Unavailable coverage:
desktopZipPythonanddesktopZipHeapexercise this path only through Python and a subprocess, and the former fails 26 tests on this Windows host at both revisions. The new test callsscanZipDirectorydirectly, so it runs everywhere.Author readiness
Human owner: @XiaoBinGan