Skip to content

fix(iso9660): read the descriptor's root record from its fixed 34-byte field - #15002

Merged
morluto merged 2 commits into
morluto:mainfrom
XiaoBinGan:fix/iso9660-root-record-length
Nov 28, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
XiaoBinGan:fix/iso9660-root-record-length

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem and outcome

parseIso9660VolumeDescriptors refused the whole image when a volume descriptor's root directory record declared a length other than 34. The descriptor reserves a fixed 34-byte field for that record — the volume set identifier always starts after it — and every common reader takes the record from the field rather than from the length byte.

Measured on origin/main with the repository's own ISO fixture, changing only the descriptor's length byte (offset 156 of the primary descriptor):

34 → parsed
36 → malformed: root directory record is not 34 bytes
48 → malformed: root directory record is not 34 bytes
20 → malformed: root directory record is not 34 bytes

Images in the wild declare 36 for a Joliet root whose NUL identifier is stored as UCS-2, and libarchive has seen up to 68. Such an image yields no inventory or extraction at all while Linux mounts it and 7-Zip, libarchive and pycdlib list it.

Evidence and validation

  • Baseline: origin/main as of the branch point. Head: 3eba997d4 on fix/iso9660-root-record-length.
  • Environment: macOS, Node 24.22.1.
  • Reproduction above is the current behaviour, captured before the change.
  • src/domain/iso9660: 23 tests pass.
  • Case added in iso9660Structures.test.ts: declared lengths 36 and 48 on the primary descriptor parse; a Joliet root declaring 36 with identifier length 2 and bytes 00 00 parses; a declared length of 20 still reports malformed with field root_directory_record.
  • Negative control, measured: reverting only iso9660VolumeDescriptors.ts fails the new case and nothing else.
  • tsc 0 errors; oxlint 0 errors; oxfmt --check clean; architecture guards pass across 3322 source files.

Contract and boundary impact

A narrower refusal. The root record is decoded from the fixed 34-byte field with the field's own length, so every other root-record check — identifier 0x00, directory flag, single extent, volume sequence number, both-endian fields — is unchanged and still runs on the same bytes.

A Joliet root whose identifier length is 2 with bytes 00 00 is read as the single 0x00 byte the record is required to carry; that normalization happens on the descriptor's own 34-byte copy, so no shared record parser gains a mode and no other caller changes behaviour.

A declared length below 34 stays malformed: it cannot hold the record's fixed fields, which is the bound libarchive also applies.

Unverified items

  • No real image from a disc or a vendor medium was tested. The reproduction is the repository fixture with one length byte changed, plus the reference-reader behaviour cited in [Bug] inspect_artifact refuses an ISO 9660 image whose descriptor root record declares a length other than 34 #14802; I have not seen such an image myself.
  • Extraction of a file from an image with a 36/48-byte root record is covered only through the descriptor and tree parse in this suite, not end-to-end through extract_artifact.
  • The directory records inside the tree are untouched: this changes only the descriptor's own 34-byte field.

Fixes #14802.

Author readiness

Human owner: @XiaoBinGan

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Problem and outcome

parseIso9660VolumeDescriptors refused the whole image when a volume descriptor's root directory record declared a length other than 34. The descriptor reserves a fixed 34-byte field for that record — the volume set identifier always starts after it — and common readers take the record from the field rather than from the length byte.

A Joliet root may store its NUL identifier as UCS-2 (length 2, bytes 00 00). libarchive has seen root records declared up to 68 bytes. Such an image yields no inventory or extraction at all while Linux mounts it and 7-Zip, libarchive and pycdlib list it.

Evidence and validation

  • Head: 6d444991bacba0017f2e81103316e47e41804d4e on fix/iso9660-root-record-length.
  • npm run test:focused -- src/domain/iso9660/iso9660Structures.test.ts src/artifacts/Iso9660ArtifactReader.test.ts src/artifacts/Iso9660ArtifactReader.boundaries.test.ts: 3 files, 105 tests passed.
  • npm run check:fast: typecheck and lint succeeded; architecture guards passed across 3322 source files. The pre-push hook ran check:fast again and it succeeded from cache.
  • src/domain/iso9660/iso9660Structures.test.ts (reads a root record from the descriptor's fixed 34-byte field) asserts structured root fields and typed failures: declared lengths 36 and 48 on the primary descriptor keep the parsed root; a Joliet root declaring 36 with identifier length 2 and bytes 00 00 keeps the Joliet root, including the one-byte identifier 0x00; the same 00 00 identifier on the primary descriptor is malformed with field identifier_length; a declared length of 20 is malformed with field root_directory_record.

Contract and boundary impact

The descriptor root is decoded from the fixed 34-byte field. iso9660DirectoryRecordAt takes that extent as the record bound instead of the length byte, so the source bytes are not copied or rewritten. Directory extents still use the length byte; those callers are unchanged.

A length-2 identifier 00 00 is accepted only for an admitted Joliet descriptor, and it is read as the required one-byte identifier 0x00. The primary descriptor still requires that single byte. A two-byte identifier does not fit the 34-byte field.

A declared length below 34 stays malformed on root_directory_record. Every other root-record check — directory flag, single extent, volume sequence number, both-endian fields — is unchanged and still runs on the field.

Unverified items

  • No real image from a disc or a vendor medium was tested. The cases are the repository fixture with the descriptor's length byte changed, and, for the Joliet case, the identifier bytes set to 00 00.
  • Extraction of a file from an image whose root record declares 36 or 48 bytes was not run end to end through extract_artifact.
  • Directory records inside the tree are unchanged. This changes only how the descriptor's own 34-byte field is bounded.

Fixes #14802.

Author readiness

Human owner: @XiaoBinGan

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.
Open in Web Open in Cursor 

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T13:58:44.581345Z 6d44499 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR reads descriptor root records from their fixed 34-byte field while accepting larger declared lengths.

  • ISO image readers use the fixed root field when its declared length is larger than 34 bytes.

Reviews (2) · Last reviewed commit: "fix(iso9660): decode the descriptor root..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eba997d43

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@morluto

morluto commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Thanks @XiaoBinGan, the bug is real: requiring the descriptor's root record length byte to be exactly 34 rejects images that Linux, 7-Zip, libarchive and pycdlib all read.

Could you rework the fix so it doesn't rewrite bytes before validation, though? The root cause is that rootRecord hands the descriptor's fixed 34-byte field to the shared self-describing iso9660DirectoryRecordAt, which trusts the record's own length and identifier-length bytes. Copying the field, setting byte 0 to 34 and turning a 00 00 identifier into length 1 makes the shared parser accept it, but it leaves that rule in the wrong place. As Codex points out, the 00 00 rewrite also applies to the primary descriptor, not only Joliet.

A cleaner shape would be:

  • Decode the descriptor's root from a fixed 34-byte view, either through an explicit fixed-extent option on the record parser or by reading the few fields the descriptor needs directly, with no mutated copy.
  • Accept the UCS-2 00 00 root identifier only for Joliet descriptors.
  • Keep a declared length below 34 as malformed on root_directory_record, as you have it.

If you can find a real image that declares 36 or more, it would be great evidence. If not, please keep the validation gap noted in the PR body.

cc @gensokyo-dev @dandgabr

The descriptor root is a fixed 34-byte field. Pass that extent to the
shared record parser instead of copying the field and rewriting its
length and identifier-length bytes. Accept identifier length 2 with
bytes 00 00 only for an admitted Joliet descriptor.
@cursor

cursor Bot commented Nov 28, 2026

Copy link
Copy Markdown

@greptileai review

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

The branch now carries the shape you asked for (6d444991b), and I verified it rather than assuming it:

  • iso9660DirectoryRecordAt takes an explicit fixedExtent — extent is the bound when the caller owns one, identifierLength is the identifier's length when the caller has established it. Other callers pass nothing, so a self-describing record still bounds itself by its own bytes.
  • rootRecord passes the descriptor's 34-byte extent and, for an admitted Joliet descriptor only, identifierLength: 1 when the field's identifier byte is 2 and both stored bytes are 00 00. No copy is mutated before validation.
  • A primary descriptor with those same bytes is not repaired: the record's own checks reject a two-byte identifier, which the added case pins.
  • A declared length below 34 still reports malformed on root_directory_record.

Verified on that head: src/domain/iso9660 23 tests, src/artifacts 2599 tests, tsc 0 errors, oxlint 0 errors, oxfmt --check clean, architecture guards across 3322 files.

On the real-image request: I have not found one that declares 36 or more. My reproduction is the repository fixture with the length byte changed, so the validation gap stays in the PR body: no disc image, no vendor medium, and extraction is covered only through the descriptor and tree parse, not end-to-end through extract_artifact. If you have an image that declares it, I will run it and record the output here.

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.

[Bug] inspect_artifact refuses an ISO 9660 image whose descriptor root record declares a length other than 34

3 participants