Skip to content

feat(apple): inspect Image4 (IMG4, IM4P, IM4M) firmware containers offline - #14907

Merged
morluto merged 13 commits into
morluto:mainfrom
mvanhorn:fix/apple-image4-containers
Nov 28, 2026
Merged

morluto merged 13 commits into
morluto:mainfrom
mvanhorn:fix/apple-image4-containers

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Apple ships boot chain components, kernel caches and coprocessor firmware wrapped in Image4: a DER IM4P payload, an IM4M signed manifest, and an IMG4 that bundles both with optional IM4R restore info. REA does not recognize these files today, so inspect-artifact reports a .im4p or .img4 as unknown bytes and there is no offline way to see the payload type, whether it is encrypted, or what the manifest declares.

This adds an apple-img4 artifact format. inspect-artifact and extract-artifact recognize the container from its content (a DER SEQUENCE whose first element is the IA5String IMG4, IM4P or IM4M), report its structure, and expose the payload, manifest and restore info as entries. Nothing is decrypted, decompressed, executed or signature-checked. Discussed in #14934. It is a read-only format-inspection addition within the supported contribution scope.

Problem and expected behavior

Use case: given kernelcache.im4p or a personalized .img4 from a restore bundle, find out what the payload is, whether it is encrypted or compressed, and which chip, board and objects the manifest names, then pull the stored payload out for the Mach-O tools.

Observable outcome:

  • Root format_metadata has kind apple-img4 and magic (IMG4, IM4P or IM4M).
  • payload reports type (such as krnl, ibot), description, the stored offset and length, compression (none, an LZFSE block magic, or complzss), uncompressed_size, payload_magic, encrypted, keybag_count and keybag_types. Keybag IVs and keys are never copied into metadata, limitations or errors.
  • manifest reports version, body properties (CHIP, BORD, ECID, CPRO, SDOM and others), per-object properties with DGST as hex, signature_size and certificate_chain_size.
  • restore_info lists properties_present with values: "redacted".
  • Entries are payload, manifest.der (the IM4M SEQUENCE without the [0] wrapper) and restore-info.der. An encrypted payload is listed and open refuses it. Compressed payloads are returned as stored with compressedSize equal to the stored length.
  • Indefinite or non-minimal lengths, constructed strings, trailing bytes, unknown tags, oversize octet strings or integers, and tag numbers that do not match their entry name are limitations, and coverage is unknown whenever one is present. A truncated value fails the read.
  • Four fixed allowances refuse excessive DER depth (32 levels), element count (4096), retained properties (256) and retained string length (4096 bytes).

Change and scope

  • src/domain/apple/image4.ts: the Image4 parser. It walks DER by header, loads nested values up to 256 KiB and walks wider ones by header so a large payload is ranged, not read. It decodes IM4P, IM4M and IM4R, keybags, compression and the four allowances.
  • src/artifacts/Image4ArtifactReader.ts: the positional reader that serves the three entries and refuses an encrypted payload on open.
  • src/domain/asn1Ber.ts: the shared BER header decoding moves into an exported readAsn1BerHeader, which also decodes high-tag-number form (needed for the PRIVATE-class MANB, MANP and BNCN tags) with a 5-octet cap and rejects non-minimal forms. Asn1BerFailure gains a truncated flag set by every failure that means the input ended early. Image4 uses that flag to fail truncated reads instead of matching message text.
  • Format registration: artifactFormats.ts, artifactFormatRecognition.ts, artifactFormatMetadata.ts, firmwareMetadata.ts, targetFormats.ts, artifactGraph.ts, artifactInventoryView.ts, ArtifactReader.ts and the PE overlay format list.
  • Docs: new docs/guides/apple/image4-containers.md, CLI examples in docs/getting-started/cli.md, docs/reference/limits-and-recovery.md, docs/reference/supported-targets.md, the docs index and sidebar, and the skill references under .agents/skills/reverse-engineer-anything/ and .cursor-plugin/. The four allowances are registered in scripts/verify/fixed-ceiling-registry.json, and scripts/ci/scopes.mjs maps the new files.

Not included: decryption, LZFSE or LZSS expansion, signature or certificate validation, and decoding IM4R values.

Contract and boundary impact

  • Semantic owner and earliest changed stage: image4.ts interprets the DER once at recognition; the reader, metadata and inventory view consume its parsed facts.
  • Contribution scope fit and linked maintainer decision: read-only inspection of a local file; not applicable (no target execution, injection, mutation, or protection recovery). Encrypted payloads are refused, not decrypted.
  • CLI and MCP/tool-catalog contract: no new tool or command. inspect-artifact and extract-artifact gain one format, apple-img4.
  • Provider, bridge, target-format, or platform compatibility: one new target format. Existing BER callers (APK v1 signatures, PE certificates) now get a decoded high tag number where they previously failed on high-tag form; their own tag checks are unchanged and their tests pass.
  • Evidence, artifact, provenance, or reconstruction contract: new apple-img4 metadata and entry metadata (decoded: false, unpacked: false).
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none committed; authored skill references updated under .agents/skills/reverse-engineer-anything/ and .cursor-plugin/.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/domain/apple/image4.test.ts (21 tests: IM4P, IM4M and IMG4 structure, keybags with and without a decodable layout, compression agreement and disagreement, complzss headers, oversize octet strings and integers, tag-name mismatches, indefinite and non-minimal lengths, trailing bytes, truncation, the four allowances), src/artifacts/Image4ArtifactReader.test.ts and src/artifacts/Image4ArtifactReader.boundaries.test.ts (the three entries per container type, encrypted refusal on open, stored LZFSE and LZVN bytes returned undecoded, truncation, a malformed high tag, each of the four allowances, and indefinite values that are not bounded), src/domain/asn1Ber.test.ts (5 tests: low and high tags, header lengths, malformed high tags, the truncated flag), plus entries in artifactFormatRecognition.test.ts, TargetFormatVocabularies.test.ts and tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. Fixtures are built in src/domain/apple/image4.fixture.ts.
  • Base reproduction or other evidence: before this change inspect-artifact does not recognize these files. The CLI output below is executed against this branch.
  • User-visible CLI/MCP output (if applicable): executed on synthetic files built with the fixture helpers (no Apple firmware used).

rea inspect-artifact sample.img4 --json on an IMG4 holding an LZFSE krnl IM4P, an IM4M and an IM4R:

kind: apple-img4, magic: IMG4
payload: type "krnl", description "KernelCacheBuilder", compression "bvx2", uncompressed_size 4096, encrypted false, keybag_count 0
manifest: version "0", CHIP "32816", BORD "4", ECID "9007199254740993", CPRO true, SDOM "1", object ibot with DGST, signature_size 15, certificate_chain_size 12
restore_info: properties_present ["BNCN"], values "redacted"
entries: manifest.der 247, payload 32 (bvx2), restore-info.der 51; coverage complete

rea extract-artifact sample.img4 --json wrote manifest.der (247 bytes), payload (32) and restore-info.der (51) with containment_verified: true and coverage complete.

rea inspect-artifact encrypted.im4p --json on an ibot IM4P with two keybags reported encrypted: true, keybag_count: 2, keybag_types: [1, 2]. The JSON contains none of the fixture IV or key bytes. rea extract-artifact encrypted.im4p --json refused with unsupported_target: "Archive entry payload is encrypted; REA does not decrypt archive entries, so the archive cannot be extracted completely".

rea inspect-artifact deep.im4m --json on an IM4M with 40 nested SEQUENCEs refused with "Image4 DER nesting exceeds 32 levels. This release has no runtime override." and { allowance: "The Image4 DER depth allowance", limit: 32, unit: "levels" }.

  • Remaining proof gaps: no shipped Apple Image4 file was used; all inputs are fixture-built. LZFSE and complzss handling is shown on synthetic headers.

Not a boundary fix. The new reader's boundary tests cover truncation, a malformed high tag, the four allowances, and indefinite or trailing data kept as limitations.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run on the seven test files above: 7 files, 143 tests passed.
  • npm run lint: exit 0, including the fixed-ceilings verification.
  • node scripts/rea.mjs inspect-artifact and extract-artifact on the fixture-built files: output as shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. readAsn1BerHeader and the truncated flag are additions. In the shared reader, a high-tag-number form is now decoded instead of refused; existing callers match on low tags and are unaffected.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. The Image4 reader never calls a decompiler or the OS loader; the tests and CLI runs above used Node 24 on an Apple silicon Mac.
  • Package or release metadata impact: one new artifact format.
  • Security, privacy, process, or containment review: reads a local file through bounded positional reads. Keybag key material and IM4R values are never surfaced. Encrypted payloads are refused on open. DER depth, element count, retained properties and string length are bounded before any per-element work.

AI was used for assistance.

Author readiness

Human owner: @mvanhorn

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • 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.

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Demo

demo

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 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-28T00:50:54.511139Z 8baff0f 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 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge based on the reviewed code.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge based on the reviewed code.

Summary

Adds offline Image4 recognition, inspection, and extraction through the existing artifact workflows.

  • REA now inspects Apple Image4 firmware files offline.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  F["Local firmware file"] --> R["Read DER magic"]
  R --> P["inspectImage4"]
  P --> M["Metadata and limitations"]
  P --> E["Stored entry ranges"]
  E --> O{"Encrypted payload?"}
  O -->|Yes| X["Refuse open"]
  O -->|No| S["Return stored bytes"]
Loading

Reviews (11) · Last reviewed commit: "Merge origin/main into fix/apple-image4-..." · Reviewed by Greptile

Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved

@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: 768ab1c7cf

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for this. I addressed the review threads with two commits on top of yours. Your history isn't rewritten.

2aecc16f8f: one field model instead of tag searches

  • Tag checks now use the decoded universal tag number, with the constructed bit checked separately. The raw identifier octet is only used in diagnostic text. That is why constructed OCTET STRING (0x24) and constructed strings (0x36) were missed before.
  • Walking: every constructed value is walked once, including the large ones read by header, so structure, depth and element accounting always apply. Walk.childrenOf caches each header-walked value's children, so every element is charged exactly once.
  • Unknown fields after a property's value, after a MANP body or manifest object, in IM4R, and in the certificate-chain slot are reported by tag and offset. No restore value is exposed.
  • Strings are decoded by tag. UTF8String goes through the shared strict UTF-8 helper. IA5String and PrintableString are checked as ASCII.
  • Integers: an unsigned 32-bit INTEGER accepts DER sign padding.
  • Recognition reads both prefix headers with readAsn1BerHeader, so it accepts the same length forms inspection does.

7fffb03ecf: field positions taken from reference implementations

  • IM4P: "IM4P", type, description, data OCTET STRING, then an optional keybag OCTET STRING, an optional compression SEQUENCE { INTEGER algorithm, INTEGER size }, and optional PAYP in [0]. This matches img4tool's isIM4P / im4pContainsKBAG (keybag at index 4 only, compression and PAYP after it) and img4lib's DERImg4PayloadItemSpecs (data, keybag, then compression and ep_info).
  • Algorithm numbers: both references define only algorithm 1, LZFSE (img4tool maps it to bvx2). Neither defines a number for complzss, so any other algorithm is reported as unknown, as before.
  • IMG4: { "IMG4", IM4P, [0] IM4M, [1] IM4R }, each read in its position.
  • IM4M: { "IM4M", INTEGER version, SET body, OCTET STRING signature, SEQUENCE certificates }, as img4tool's isIM4M checks.
  • IM4R: { "IM4R", SET of [PRIVATE] { IA5String name, value } }, for example BNCN.
  • Slot rule: a value outside its slot is reported and never takes another field's role, and an EXPLICIT wrapper holds exactly one value.
  • Where the references and the code disagree:
    • Both references require the description, but this reader still tolerates a missing one. It reports the omission and leaves description null.
    • img4tool requires manifest version 0, but this reader reports any unsigned version.
  • Unknown vs. absent: description is null when absent or undecodable, not "". An undecoded keybag reports keybag_count and keybag_types as null (unknown) instead of 0/[]. A decoded keybag counts every entry, even one whose type doesn't fit in 32 bits.

DER handling. X.690 DER forbids constructed string encodings and non-minimal lengths. This reader keeps your tolerant approach: such values are reported as limitations, coverage becomes unknown, and they're never decoded into facts. A constructed payload or keybag is never exposed as plain bytes.

Sources: DeepWiki answers for tihmstar/img4tool (img4tool/img4tool.cpp) and xerub/img4lib (libvfs/vfs_img4.c). DeepWiki hadn't indexed 1Conan/pyimg4 or m1stadev/PyIMG4, so those weren't checked.

Every review thread has a reply with its regression, and each new test fails on 768ab1c7cf.

Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved

@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: 7fffb03ecf

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved

@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: 7fffb03ecf

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

I did a brittleness pass on top of my earlier two commits and pushed it as 323b3c1ec6.

Fixed

  • Unknown reported as absent:
    • An encrypted payload without a compression field reported compression: "none". So did a declared algorithm other than 1 when the bytes had no known magic. Both now report "unknown", a new value in the compression enum, with a limitation. Encrypted bytes have no readable magic, so only the compression field can describe them, which is also how pyimg4 decides.
    • A string too large to parse as a tree used to come back as absent. It is now refused with the string allowance.
  • One decision made in two places:
    • The retained-text allowance was checked in both Walk.readValue and ia5Text. Only ia5Text checks it now, and only for text that is actually kept.
    • The canonical-BOOLEAN check ran in both the structural pass and decodeBoolean. Only the structural pass runs it now.
  • Raw identifier byte: the keybag's inner SEQUENCE was checked by its first byte being 0x30. It is now parsed with the shared decoder and checked by its universal tag.
  • Manifest version: a version other than 0 now gets a limitation. img4tool's isIM4M accepts only 0, and no reference describes any other version.
  • Named constants:
    • IMAGE4_MANIFEST_VERSION.
    • IMAGE4_COMPRESSION_LZFSE: 1 is the only algorithm number img4lib, img4tool and pyimg4 decode.
    • IMAGE4_PREFIX_BYTES.
    • The UNIVERSAL tag table.
  • Tests that only mirrored the implementation: a new golden test builds an IM4P byte by byte in hex, without the fixture builders. It covers the type, description, data, a keybag with a 16-byte IV and a 32-byte key (as in img4lib's makeKeybag), and LZFSE compression. It checks the exact facts, including the payload offset.
  • Positional and first-match parsing: covered by the earlier commit 7fffb03ecf. That commit reads IM4P, IMG4, IM4M, IM4R and EXPLICIT wrappers field by field in order.

Left as is, on purpose

  • Missing description is tolerated. The references require it, but this reader keeps reporting the omission and setting description to null instead of refusing the file.
  • The four artifactFixedLimitFailure declarations in Image4ArtifactReader stay written out. I tried a table, but the fixed-ceiling registry check needs the allowance name as a literal at each declaration.
  • The remaining lint warnings stayed: max-params on consumeManifest and takeProperties, and complexity on inspectImage4. They are warnings, not errors, and reducing them would mean restructuring the recursion without fixing any defect.

Sources

  • DeepWiki: tihmstar/img4tool (img4tool/img4tool.cpp: isIM4P, im4pContainsKBAG, isIM4M, IM4R builders) and xerub/img4lib (libvfs/vfs_img4.c: DERImg4PayloadItemSpecs, makeKeybag).
  • context7: /m1stadev/pyimg4 (parser.py IM4P parse order and _detect_compression).
  • All three agree on the field order: IM4P data, then an optional KBAG OCTET STRING, then an optional compression SEQUENCE whose first INTEGER is 1, then an optional PAYP in [0].
  • pyimg4's Compression IntEnum (LZSS=1, LZFSE=2) is that library's own internal numbering, not the value on the wire.

CI: the only real failure on 7fffb03ecf was tests/boundary/cli/cliOptionAliases.test.ts. It comes from main's lipo -thin wording in the help text of inspect-dwarf-units, inspect-go-binary, inspect-native-initializers and inspect-rust-binary (#14881), not from this PR. #14912 fixes it. The other shards were cancelled after that failure.

@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: 323b3c1ec6

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
mvanhorn and others added 4 commits November 27, 2026 09:28
…fline

Image4 files are recognized from a DER SEQUENCE whose first element is
the IA5String IMG4, IM4P, or IM4M, independent of the filename, and are
inventoried as apple-img4. The stored payload octet string is exposed as
payload, the embedded IM4M sequence as manifest.der, and the IM4R
sequence as restore-info.der. Keybags contribute a count and key types,
with initialization vectors and keys left out of metadata; an encrypted
payload is refused on open; signatures and certificates are reported by
size; LZFSE and complzss payloads stay compressed; IM4R property names
are listed and their values stay redacted. Four fixed allowances refuse
excessive DER depth, element count, property count, and string length,
and inventory coverage is unknown whenever a limitation is recorded.
Compare universal tag numbers instead of identifier octets, so constructed
OCTET STRING and string values are recognized and reported. Read IM4P fields
by position so an unsupported payload keeps its slot and a constructed keybag
still marks the payload encrypted. Walk every constructed value once, caching
the children of header-walked values so each element is charged once, and
check large values a consumer does not decode. Report unknown restore members,
extra property and object fields and a mistyped certificate chain. Decode
UTF8String as UTF-8, accept DER sign padding on unsigned 32-bit integers, and
recognize the magic with the shared BER header decoder.
…nts null

Follow img4tool and img4lib: after the payload, an optional keybag OCTET
STRING, then an optional compression SEQUENCE, then PAYP in [0]; IMG4 holds
IM4P, [0] IM4M and [1] IM4R in that order. A value outside its slot is
reported as unknown and never takes another field's role, and an EXPLICIT
wrapper holds exactly one value. An absent or undecodable description is
null rather than empty, and an undecoded keybag reports a null count and
types instead of zero; a decoded keybag counts every entry.
An encrypted payload without a compression field, or a declared algorithm
other than LZFSE with no recognizable magic, now reports compression
"unknown" instead of "none". Make ia5Text the single owner of the
retained-text allowance so a string too large to tree-parse is refused
rather than reported absent, keep the canonical BOOLEAN check in the
structural pass only, check the keybag's inner SEQUENCE through the shared
decoder instead of its first octet, note a manifest version other than 0,
and name the spec constants after their sources. Add a hand-encoded IM4P
golden that does not use the fixture builders.
@mvanhorn
mvanhorn force-pushed the fix/apple-image4-containers branch from 323b3c1 to b4db59c Compare November 27, 2026 17:28
A value whose end cannot be found keeps its identifier, so a stopped keybag
still marks the payload encrypted and a stopped payload keeps its slot; the
values after it become a limitation. The IMG4 payload slot is consumed
whatever it holds, so an unsupported value does not hide the manifest and
restore slots. A property body that is not a SET or SEQUENCE is reported
instead of read as empty, and an entry whose name cannot be read is one
unknown entry whose value is never walked for more names, so restore values
stay redacted. Load a value only when it may be decoded and fits an 8 MiB
retained budget; larger primitives and values past the budget are walked by
header.
Comment thread src/domain/apple/image4.ts Resolved
Comment thread src/domain/apple/image4.ts Resolved

@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: f41fe00c6e

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
A PRIVATE-tagged restore value is one property: only its name is reported,
and its value is never searched for names, even when the name is unreadable
or is IM4R. Only the IM4R property SET is walked as a container. Small
primitives are always loaded, so names and scalars stay readable after the
retained budget is used. A declared uncompressed size that is negative or
not an exact integer is reported as a limitation.
Comment thread src/domain/apple/image4.ts Resolved

@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: 53d324898a

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
…TE manifest entries opaque

Reserve retained bytes only for a value that will be tree-parsed, so a
ranged wrapper around a large payload no longer uses budget a later small
indefinite value needs. A PRIVATE manifest entry must name itself; when its
name cannot be read it is reported and its value is never interpreted as
manifest facts.

@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: f9ed1e0a6b

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
# Conflicts:
#	docs/reference/supported-targets.md
#	scripts/ci/scopes.mjs
#	scripts/verify/fixed-ceiling-registry.json
#	tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts
A MANB, MANP or IM4R entry that holds only its name is a missing body, not a
confirmed-empty one, so it is reported as a limitation while sibling facts
are kept.
Comment thread src/domain/apple/image4.ts Resolved

@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: 555fbd8419

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
# Conflicts:
#	docs/reference/supported-targets.md
A context-, application- or other-tagged manifest value that begins with a
name is unsupported structure, reported as an unknown tag rather than read
as a manifest entry.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 21:39

@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: df15cc6686

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/apple/image4.ts Resolved
One slot assigner owns the IMG4 layout: a context-tagged value fills the
slot with its tag number, skipping earlier optional slots, and any other
value occupies the next slot even when it cannot fill it. An unsupported
manifest value therefore no longer hides a following [1] IM4R.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 22:07
@morluto
morluto disabled auto-merge November 27, 2026 22:30
@morluto
morluto enabled auto-merge (squash) November 27, 2026 22:34
@morluto
morluto disabled auto-merge November 27, 2026 22:36
@morluto
morluto enabled auto-merge (squash) November 27, 2026 22:37
@morluto
morluto disabled auto-merge November 27, 2026 22:38
@morluto
morluto enabled auto-merge (squash) November 27, 2026 22:42
@morluto
morluto disabled auto-merge November 27, 2026 22:45
@morluto
morluto enabled auto-merge (squash) November 27, 2026 22:47
@morluto
morluto disabled auto-merge November 27, 2026 22:51
@morluto
morluto enabled auto-merge (squash) November 27, 2026 23:04
@morluto
morluto disabled auto-merge November 27, 2026 23:06
@morluto
morluto enabled auto-merge (squash) November 27, 2026 23:14
@morluto
morluto disabled auto-merge November 27, 2026 23:16
@morluto
morluto enabled auto-merge (squash) November 27, 2026 23:29
@morluto
morluto disabled auto-merge November 27, 2026 23:31
@morluto
morluto enabled auto-merge (squash) November 27, 2026 23:34
@morluto
morluto disabled auto-merge November 27, 2026 23:36
@morluto
morluto enabled auto-merge (squash) November 28, 2026 00:07
Keep the Image4 and Mega Drive registrations that both sides added.

Co-authored-by: morluto <[email protected]>
@morluto

morluto commented Nov 28, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@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: 8baff0f7bb

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1316 to +1317
compression = await asCompression(compressionSlot, walk, depth + 1, notes);
if (compression === undefined) unknownTag(compressionSlot, notes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep undecodable compression fields distinct from absent fields

For an IM4P without a keybag or recognized payload magic, a compression slot such as SEQUENCE { INTEGER 1 } makes asCompression return undefined, conflating an unreadable compression declaration with an omitted field. Probes reproduce this in both parsing strategies: buildPayload publishes compression: "none", which the reader also maps to compressedSize: null, despite the declaration indicating LZFSE. Preserve a present-but-undecoded state, or retain the readable algorithm with an unknown size, rather than advertising these stored bytes as uncompressed.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@morluto
morluto merged commit 88373e3 into morluto:main Nov 28, 2026
57 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

@morluto thanks for merging this, and for the follow-up commits that tightened the field model. Really appreciate inspect-artifact being able to read Image4 containers offline now.

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.

3 participants