Repository navigation
fix(zstd): share exact-frame Zstandard decoding across ELF and OTA - #12416
Conversation
Walk RFC 8878 frames once so ELF sections, Android OTA REPLACE_ZSTD, and GPU payloads reject truncated headers, blocks, checksums, and trailing bytes on every supported Node runtime. Bound that walk with the runtime zstd.max_frames setting.
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32d64326d3
ℹ️ 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".
[High impact] The shared framing rules reach several binary-analysis and artifact-reading workflows. The interrupted debug-link report must preserve saved Evidence before merging to satisfy the repository requirement.
|
Copy each Node 22 frame off its decoder chunk before the next frame is decoded. Map a GPU zstd.max_frames refusal through the resource-limit contract instead of a provider failure. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a49b5ee405
ℹ️ 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".
…ults Project zstd.max_frames through one resource-limit helper for ELF notes, DWARF, GPU, and artifact reads. An invalid REA_ZSTD_MAX_FRAMES seed stays a configuration failure, and frame-header tests cover content size, window, dictionary id, and RLE blocks. Co-authored-by: morluto <[email protected]>
The frame-by-frame fallback awaits a caller pause before each data frame. GPU yields and checks the read signal there, so a many-frame payload does not finish before a disconnect is observed. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b5dd2eb5a
ℹ️ 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".
…able List every operation that enforces zstd.max_frames, including GPU, DWARF, and ELF notes. The strict sequence uses the async decoder and checks the caller signal again after it returns, and a single output buffer is not copied a second time. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17d71b1b69
ℹ️ 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".
Regenerate the advertised input summaries for inspect_analysis_settings and update_analysis_settings. GPU inventory now throws the projected zstd.max_frames resource limit from payload decode and #retainFailure, so the adjustable setting survives the public failure. Co-authored-by: morluto <[email protected]>
oxfmt keeps the zstd.max_frames throw in #retainFailure on one line so CI format:check matches the local formatter. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bef8a752c
ℹ️ 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".
The fallback returned success in the same turn as the final synchronous frame, so a queued abort was still invisible to the caller's signal check. Pause once more before that success, matching the strict sequence. Co-authored-by: morluto <[email protected]>
The synchronous frame loop ignored abort signals owned by inspect_elf_notes, inspect_dwarf_units, and Android OTA partition reads. Those callers now use the cooperative decoder and yield before Zstandard work, and 32-frame cancellations cover each path. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d636d4b7b
ℹ️ 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".
…tive-structural-walk # Conflicts: # src/artifacts/AndroidOtaPayloadArtifactReader.boundaries.test.ts # src/artifacts/AndroidOtaPayloadArtifactReader.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 975c14d4b7
ℹ️ 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".
readElfDirectoryFromBuffer now requires the caller's operation and throws the adjustable zstd.max_frames resource limit. Hardening, unwind, and the other directory consumers keep that typed refusal instead of an adapter or I/O error. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f02dfc7148
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3bde307b5e
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cd35954da
ℹ️ 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".
These inspections already own an abort signal. Their ELF directory read now uses the cooperative container decoder so a queued cancellation can land during a many-frame section-name table. Co-authored-by: morluto <[email protected]>
The cooperative module reader decoded the bytes as ELF before the container check, so gzip, xz, and zstd modules became malformed images. The compression check now returns the unsupported-container report first. Co-authored-by: morluto <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c1969f940
ℹ️ 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".
| const unverifiedCandidateObservation = ( | ||
| report: ElfDebugLink, | ||
| candidate: ElfDebugCandidateFile, | ||
| ): ElfDebugLink => ({ | ||
| ...report, | ||
| candidate: { | ||
| path: candidate.path, | ||
| sha256: candidate.sha256, | ||
| bytes: candidate.bytes, | ||
| format: null, | ||
| byte_order: null, | ||
| debug_info: "unknown", | ||
| symtab: "unknown", | ||
| }, |
There was a problem hiding this comment.
Cancelled reports bypass Evidence storage
When cancellation stops comparison after the candidate read completes, unverifiedCandidateObservation returns a non-null candidate with verification: null. ElfDebugLinkService.verificationAgrees rejects that pair, so the service never creates Evidence for the report. MCP keeps the completed image report and candidate identity inline but cannot save them for later calls.
Add an explicit path for this partial report and test it through the service. The repository requires preserving Evidence provenance and session semantics through both adapters; this requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Knowledge Base Used: Binary diagnostics and comparison
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/native/elf/ElfDebugLinkProvider.ts
Line: 186-199
Comment:
**Cancelled reports bypass Evidence storage**
When cancellation stops comparison after the candidate read completes, `unverifiedCandidateObservation` returns a non-null `candidate` with `verification: null`. `ElfDebugLinkService.verificationAgrees` rejects that pair, so the service never creates Evidence for the report. MCP keeps the completed image report and candidate identity inline but cannot save them for later calls.
Add an explicit path for this partial report and test it through the service. The repository requires preserving Evidence provenance and session semantics through both adapters; this requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
**Knowledge Base Used:** [Binary diagnostics and comparison](https://app.greptile.com/-/switch-tenant?tenant=pre&next=%2Fcustom-context%2Fknowledge-base%2Fmorluto%2Frea%2F-%2Fdocs%2Fbinary-diagnostics-and-comparison.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Closes #12398 and #12447.
ELF compressed sections and Android OTA
REPLACE_ZSTDoperations accepted incomplete Zstandard input when they trusted the decoder's consumed-byte count. That check, introduced for review in #12382 and #12383 by @ShuaixinHuang, rejects some valid suffix frames on Node 22 and still accepts a truncated checksum or a partial next-frame magic on the runtimes where the count is reported. This PR replaces both byte-count checks with one shared exact-frame decoder.Problem and expected behavior
RFC 8878 allows concatenated and skippable frames. A complete stream must include each frame header, every block, and the optional 4-byte content checksum. Trailing garbage and a partial next-frame magic are not part of that stream.
Node 22.23.4 stops after the first frame and can return the declared output when the checksum bytes are missing. Node 24.22.1 and Node 26 accept a full sequence, but
bytesWrittencan include a 1–3 byte prefix of the next magic.rejectGarbageAfterEndcloses that suffix case only where the runtime actually implements it.Change and scope
src/domain/compression/zstandardExactFrame.tswalks each frame per RFC 8878 §3.1. The walk, not the decoder's byte count, decides the frame boundary. Where Node decodes a whole sequence andrejectGarbageAfterEndrejects a trailing byte, one strict decode consumes the walked span. Otherwise each walked frame is decoded on its own, and each output is copied off the decoder chunk before the next frame. A single output buffer is returned as that buffer.zstd.max_frames(REA_ZSTD_MAX_FRAMES) is a runtime setting: default 4096, floor 1, maximum 65536. It is listed for the artifact, GPU, DWARF, ELF note, hardening, unwind, export, initializer, kernel-module, debug-link, Go, Rust, IL2CPP, and Android JNI operations that read an ELF directory or decode Zstandard. Exceeding it iswork_limit.readElfDirectoryFromBufferrequires the caller's operation and throwsprojectZstandardFrameAllowance, so a section-name frame cap is anAnalysisResourceConstraintErrorwhoselimit.settingiszstd.max_frames. GPU inventory throws that projected error from payload decode and#retainFailure. An invalid launch seed is aConfigurationError, not malformed content.decodeZstandardFramesCooperativeis the yield point. GPU payload decode,inspect_elf_notes,inspect_dwarf_units, and Android OTA partition reconstruction pass the caller's existing abort signal into that pause. The frame-by-frame fallback awaits the pause before each data frame and once more before success. The strict sequence uses the async decoder and pauses again after it. ELF directory reads that already own a cancellation signal use the cooperative reader: hardening, unwind, exports, initializers, kernel modules, debug link, Android JNI, Go, Rust, and IL2CPP. Go, Rust, and IL2CPP go throughreadBinaryContainerCooperativewhen the inspection has a signal. A compressed kernel module is recognized before that ELF read and stays an unsupported container. SynchronousparseElfNotesandreconstructAndroidOtaPartitionremain for callers that have no signal.ZIP method 93 stays on zip.js streaming and uses the same frame grammar. It writes at frame boundaries for Node 22 compatibility and validates the final frame before reporting EOF. #12461 supplied the ZIP change. CRC, decoded size, and staged extraction remain owned by the ZIP reader and extractor.
Follow the contribution scope. Contribution scope: not applicable. This stays inside the existing read-only decode of files and captured data.
Contract and boundary impact
decodeZstandardFramesowns Zstandard framing.readElfDirectoryFromBufferprojects a section-name frame cap throughprojectZstandardFrameAllowancefor the operation the caller names.zstd.max_framesis a runtime analysis setting. No new tool. The setting registry now names the additional ELF directory operations.npm run verify:advertised-schemas -- --update-summaryreported no compact-digest change.locateDwarfSectionsis asynchronous so it can await that pause.reason. A frame-count refusal is a resource limit. An invalid seed is a configuration failure. A cancelled GPU, ELF note, DWARF, hardening, or unwind read stayscancelled.npm run verify:advertised-schemas -- --update-summaryrefreshed the input compact digests forinspect_analysis_settingsandupdate_analysis_settings. The same command after the directory projection reported no further digest change.Expected effects:
Evidence and regression coverage
inspect_analysis_settingsincludeszstd.max_framesfor each enforcing operation and provider. A 32-frame GPU payload aborted before its promise settles isreason: "cancelled"on Node 22 and Node 24.22.1. The same 32-frame cancellation is covered forinspect_elf_notes,inspect_dwarf_units, and Android OTAREPLACE_ZSTDreads. Hardening and unwind tests assertAnalysisResourceConstraintErrorwithlimit.settingzstd.max_frames,sourceruntime, and the floor and maximum, and assertAnalysisCancelledErrorwhen a many-frame section-name read is aborted. The cooperative decoder also refuses success when the first pause records an abort and the required second pause observes it.inspect_analysis_settingslistszstd.max_framesfor the operations above. A work refusal names that setting. A cancelled read of those providers stays cancelled.parseElfNotesandreconstructAndroidOtaPartitionwithout a pause, still block the event loop. The async strict decoder cannot abort the native call itself; the signal is observed when that call returns. A frame that fails inside the last synchronous decode can still return that failure before a queued abort is observed. Peak heap during 65,536 frames was not sampled.For evidence-bearing changes:
Validation performed
npx oxfmton the changed files — completed.npx oxfmt --checkpasses for the cooperative cancellation files.npm run check:fast— typecheck, lint, and architecture guards passed, including afterc29d6a41e. That script does not runformat:check.npm run test:focused --analysis settings, GPU payload, and exact-frame suites — passed on Node 22.23.4.npm run verify:advertised-schemas -- --update-summary— updated the input compact digests forinspect_analysis_settingsandupdate_analysis_settings. Packaged catalogs were listed and the checked engines accepted the patterns. Re-run after the directory projection; no digest changed.npm run test:focused -- src/gpu/GpuPayloadCodec.test.ts tests/boundary/gpu/codeObjects.test.ts src/application/AnalysisSettings.test.ts src/resources/ArtifactOperationFailure.test.ts— 166 passed, 1 skipped, on Node 22.23.4 after the GPU projection change. GPU payload and code-object tests passed again after the directory-driver change.1dea3c3aa: Build package and Documentation passed. Static checks failedformat:checkonsrc/gpu/GpuInventory.ts.6bef8a752(run 44567169009): Static checks, Build package, and Documentation passed. A duplicate Conventional PR title check was cancelled.975c14d4b7, the shared structural walk now yields while examining frame and block headers, and the GPU kernel directory reparse uses its owning signal. Both regressions failed before the patch and passed afterward.check:fast, changed TypeScript formatting, and diff checks passed. Hosted CI for that revision was pending at the time.f02dfc714:npm run check:fastpassed. Focused hardening, unwind, analysis-settings, ELF notes, DWARF, and native-directory tests passed, 77 tests. The hardening and unwind cases assert the typedzstd.max_frameslimit fields.c29d6a41e:npm run check:fastpassed. Kernel-module parser and filesystem tests passed, 31 tests. gzip, xz, and zstd containers return the unsupported report through the service before any ELF decode.a7f54c26c:npm run check:fastpassed. Go provider, Rust budget, and IL2CPP image-cancellation tests passed, 24 tests. A many-frame ELF section-name read aborts as cancellation when the inspection has a signal.3bde307b5:npm run check:fastpassed. Focused hardening, unwind, kernel-module, debug-link, and native-export tests passed, 72 tests, including the hardening and unwind cancellation cases.At
9c1969f940, all 81 focused tests andcheck:fastpassed. The kernel-module entry points share one compression classification rule. IL2CPP retains the prior generic-layout refusal order, the native mapping checkpoints, typed cancellation, and selected artifact evidence. Stacked #12472 is included at0126135170. It reuses admitted compressed section names for build-ID notes and carries cancellation to any remaining decode. The squash tree matches the tested stack head, which passed 640 tests with one existing skip andcheck:fast.Hosted Static checks flagged formatting in five section-reader tests. At
338bf90157, the full formatter check passed and the five focused suites passed 201 tests with one existing skip.The hosted retry at
338bf90157reproduced the Hopper lease fixture timeout from the first attempt. The fixture repair landed separately in #12481. This branch now includes it through the merge of main atc361039007. The combined revision passed the full formatter and all 25 focused Hopper cleanup and ELF debug-link tests. Hosted checks and exact-revision review are rerunning.Compatibility, safety, and release
readElfDirectoryFromBuffernow requires the caller's operation name.locateDwarfSectionsreturns a promise. Truncated checksums and trailing bytes are malformed. Streams with more than 4096 frames needzstd.max_framesraised, up to 65536.The optional-evidence follow-up passed 404 incremental tests with one existing skip and 357 native and lifecycle tests. The ZIP change passed 66 focused tests on each supported Node floor and 30 compiled ZIP integrity tests. After the squash, the combined head passed 112 tests. Main integration at
86d80bccb1incorporates merged #12449 and passed 233 focused tests with one existing skip, pluscheck:fast. Hardening now uses cooperative ELF directory decoding when the provider has a signal. At6d9623ca92, the cancellation regression passed, along with 354 focused tests, 419 incremental tests, 84 Node 22 and 84 Node 26 controls, andcheck:fast. The broader sibling audit and hosted checks are pending.At
9cd35954da, unwind and exports observe owned cancellation while reading ELF section names. Initializers and JNI share a single directory read for their mappings and section facts. Native exports retain the existing symbol-row checkpoints. The optional debug-link comparison retains the completed candidate identity on cancellation and reports capped candidate facets as unknown. The combined branch passed 295 tests across eight focused suites, pluscheck:fast. Hosted checks remain pending. Go, Rust, and IL2CPP now use the cooperative container reader when their inspection has a signal.Author readiness
Human owner: @morluto
Before merge
type(scope): outcome.