Skip to content

A6: ZIP archive screening - #2392

Merged
neuromechanist merged 12 commits into
feature/issue-2182-epic-pq-evidencefrom
feature/issue-2185-zip-reader
Nov 26, 2026
Merged

neuromechanist merged 12 commits into
feature/issue-2182-epic-pq-evidencefrom
feature/issue-2185-zip-reader

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2367. Part of #2182.

Card A6 of the publication-queue plan: a .zip is screened by its entry names, and small inner recordings in a format with a registered reader are read by that reader. Anything not read is reported under its inner format as zip:<ext>.

What changed

  • shared/readers/zip.ts: the end record from the last page of the archive (the rest of the last 64 KiB, and a maximal comment, only when it is not there), ZIP64 locator and end record, then the central directory, capped at 4 MiB and 50,000 entries (partial, limit past either). Split archives are partial (unsupported-version); a missing or inconsistent end record is partial (corrupt); an archive of unknown size is partial (limit).
  • Entry names go through scanPaths as <archive>!/<entry>; inner readers get the same path. The path rules' hits are folded to one finding per kind per archive, with the number of entries it stands for in the new optional Finding.entries (a count, never a name). path-subject-label still fires.
  • An entry is read when its extension has a reader, its method is stored or deflate, its uncompressed size is at most 64 MiB and it is not encrypted. Deflate is inflated lazily with DecompressionStream("deflate-raw") (16 KiB of input at a time), only as far as the inner reader reads, and never past the declared size: more output than declared is corrupt (the zip bomb case). Inflated bytes of all entries share the reader's maxInflatedBytes.
  • Not read (no reader, other method, over the size cap, inner not-applicable, a nested .zip) counts as zip:<ext>; encrypted entries are counted so and make the archive partial (encrypted). The archive is complete only when every inner entry that was read was read completely (inner partial reasons, companion gaps, limits and time all carry through). A failed read of the archive itself is a failed read of the archive.
  • What counts as an inner recording is the registry's own formatCoverage, applied as if the archive's content sat under sourcedata/; macOS resource forks (__MACOSX/, ._name) are screened by name and never read.
  • ReaderResult.unscreened (new, optional): readRecordings adds it to notApplicable, which every caller already counts as unscreened, so zip:<ext> reaches unscreened_formats with no caller change.
  • Registered as ZIP_READER. The reader imports the registry only as types; the registry hands it its functions (ZipKit), so there is no module cycle and the inner registry excludes ZIP (one level of nesting).
  • No new incomplete reason or failure class: encrypted, corrupt, limit, time, unsupported-version and companion-missing already have their copy entries.
  • Lead ruling, A2 fix: NIRx Name= in [Subject Demographics] goes through readSubjectId, the rule SNIRF SubjectID and EEGLAB subject share. A name-like word of letters only stays nirx-subject-name (identifier); other text with a name-like word in it (letters fused with digits, an underscore-joined participant and session code) is the new kind nirx-subject-freetext (review, with its KIND_COPY entry); the BIDS label and short codes are nothing. Operator and experimenter fields keep their rule.
  • scripts/dev/reader-fp-measure-remote.ts: full https:// keys (Zenodo content links), a name column, 429/503 back-off, and a total of unscreened inside files.

Tests

  • test/readers-zip.test.ts (29 tests): Info-ZIP fixtures built from the repository's EDF fixtures (test/fixtures/zip/README.md records commands, the throwaway password and SHA-256): inner EDF findings and zip:.xdf, nesting, ZIP64 (zip -fz), encrypted (zip -P), truncation, a crafted bomb (declares 1 KiB, inflates to 100 MiB). Archives a stock tool cannot make are written byte for byte in the test (methods, caps, split, 50,000 entries).
  • test/identifier-fleet.test.ts: an archive's inner findings and zip:.xdf reach the record; nested and encrypted archives.
  • Bytes read for an archive whose entries all lack readers: at most the directory plus 64 KiB plus the 22-byte end record (the page cache fetches from the directory's page start).
  • Mutation check: 28 + 5 mutations (the fold and the NIRx rule added 5), one at a time, all killed, including both directions of each cap (entries 50,000, directory 4 MiB, entry 64 MiB).

Gates on the head: bun run typecheck clean; bun run lint "Checked 209 files ... No fixes applied."; biome on every touched file clean; bun test test/readers-zip.test.ts test/identifier-fleet.test.ts test/readers-nirx.test.ts test/identifier-coverage-contract.test.ts test/identifier-screen-report.test.ts test/identifier-scan.test.ts test/readers-snirf.test.ts 427 pass, 0 fail. Pure tier (before the merge of A9): 28,002 pass, 6 fail; 2 were registry lists in identifier-coverage-contract.test.ts (fixed here), the other 4 also fail on the base (account-copy-parity against the local website checkout, git-annex-remote UUID retry) or were load timeouts that pass alone (completion-argv-guard). Live tier not awaited (phase-PR gate).

False-positive gate (owner rule): met under the lead's ruling

461 public archives from 254 records: 412 Zenodo EEG/MEG/iEEG/fNIRS/EMG dataset records (up to 3 zips each) and 49 OpenNeuro zips (ds001810 sourcedata, ds003702 derivatives), central directories read by HTTP range requests, nothing downloaded whole. 409 read (400 complete, 9 partial: 7 limit, 1 corrupt, 1 companion-missing); 52 refused by Zenodo with 429. Bytes per complete archive p50/p90/max: 46 KB / 189 KB / 3.3 MB. Rates are per 100 read archives, recomputed for the fold (one path finding per kind per archive) and with the NIRx record (3 archives) measured again after the NIRx fix.

kind severity per 100 archives records
nirx-subject-name identifier 0.00 (was 1.22) 0
nirx-subject-freetext review 1.22 1
image-or-document-file review, inherited path rule (exempt) 23.72 78
tooling-debris review, inherited path rule (exempt) 10.51 31
path-subject-label review, inherited path rule (exempt) 1.71 3
brainvision-segment-date date kind (never gates) 27.63 5
edf-startdate date kind 2.93 2
edf-recording-startdate date kind 2.69 1
nirx-header-date date kind 1.71 1
  • Identifier: 0. The one record that had 1.22 per 100 held a participant and session code in a NIRx .inf Name= (shape A99_A9_A9_A+9); after the NIRx fix it is nirx-subject-freetext (review).
  • Review, this reader's own kinds: 1.22 per 100, under 5.
  • Lead ruling: the inherited path kinds (image-or-document-file, tooling-debris, path-subject-label) are exempt from this reader's 5-per-100 review gate. They are the dataset-level path rules applied to entry names, now one finding per kind per archive, and their volume is handled by the batch acknowledgment.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2392

Version: 0.10.40-PR2392.14da31c
Commit: 14da31c


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Merge gate (lead): head 14da31c. Every remote check passes after one rerun of integration shard 3, which failed in an unrelated compute end-to-end test (compute-user-e2e-cli: a webhook stand-in with no subscription). Review: round 1 panel, 2 important parser findings (entries hidden by an undercounted end record; a NaN size that could hang the inflater) and 5 more fixed; round 2 delta found 1 important (the directory must end at its end record), fixed in 05b48f7 and verified by the lead. The lead's mutation of the ZIP64 end-record size check survived, and the test added in 14da31c now catches it. Local entries outside the central directory, and local-versus-central names, are documented as out of scope with the reason.

@neuromechanist
neuromechanist merged commit eab1533 into feature/issue-2182-epic-pq-evidence Nov 26, 2026
59 of 61 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2185-zip-reader branch November 26, 2026 03:33

This branch was previously deployed

1 inactive deployment
npm — 14da31cc Deployed Nov 26, 2026 by neuromechanist via publish #4957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant