Repository navigation
fix(elf): reject unconsumed Zstandard section bytes - #12382
ShuaixinHuang wants to merge 2 commits into
Conversation
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. |
[Medium impact] The code appears safe to merge; no new correctness or security issue was found. SummaryThe shared ELF decoder now rejects Zstandard section bytes that the decoder did not consume, matching the existing zlib check.
ShuaixinHuang acknowledged proceeding without a separate issue. The fix is not already present in the supplied target commit. Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/elf-zstd-se..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adbdf9aba8
ℹ️ 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".
| if (result.consumedBytes !== payload.length) | ||
| return { | ||
| state: "malformed", | ||
| message: `${subject} has bytes after its ${compression} stream`, |
There was a problem hiding this comment.
Distinguish valid Zstandard suffix frames from trailing garbage
When a section contains a valid empty or skippable Zstandard frame after its data frame, the synchronous decoder can stop at the first frame, so this comparison incorrectly marks the section malformed. Appending zstdCompressSync(Buffer.alloc(0)) preserves the declared output size and was accepted by the base decoder, but is rejected here; libzstd 1.5.5 successfully decompresses the full sequence. This also makes readElfDirectoryFromBuffer throw for an otherwise readable compressed .shstrtab. I reproduced the decoder and directory failures on the available Node 24.15.0; the pinned runtime was unavailable. Validate and consume permitted subsequent frames within the existing aggregate bounds, and add an accepted suffix-frame control alongside the garbage-byte regression.
AGENTS.md reference: AGENTS.md:L105-L105
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed a compatibility problem on supported Node 22.23.4. It stops after the first frame even for a valid empty or skippable suffix. It can also report all bytes consumed and return the expected decoded size with a truncated checksum. Pinned Node 24.22.1 and supported Node 26.12.1 accept complete suffix frames but can report a 1–3-byte prefix of the next frame magic as consumed. The newer strict suffix option closes that case there. Node 22 exposes no completion status, so bytesWritten alone cannot prove exact framing across supported versions. Holding this thread open while the shared ELF compression owner is investigated.
There was a problem hiding this comment.
I tested a shared frame scanner and a Node 22 continuation path on the three supported runtime minima. Valid suffixes and checksum truncation now classify correctly in the prototype. Its synchronous Node 22 fallback took 260–361 ms CPU for 65,536 small productive frames, and existing ELF byte allowances admit millions. I recorded the exact-decoding and work-policy decision in #12398. The current head still needs this review finding addressed before merging.
There was a problem hiding this comment.
Rechecked the merged-base head 1442080ec1 on Node 22.23.4, 24.22.1, and 26.12.1. The decoder and fixtures are unchanged. Node 22 still rejects complete suffix frames and accepts a truncated checksum. Node 24 and 26 still accept partial next-frame magic. The high frame-count control continues to report only the existing byte limit. This thread remains open and #12398 records the work-bound decision.
|
Superseded by #12416, now merged into main. The shared exact-frame reader rejects unread bytes in ELF Zstandard sections. The ELF regression covers a valid frame, a legal skippable suffix, and rejection of a trailing byte. Thanks for identifying the ELF case. |
Summary
Node's Zstandard decoder can return the expected output while consuming only part of the compressed section. On main an otherwise valid frame followed by an unread byte was returned as available.
Change and scope
Use the decoder's consumed-input count for ELF sections, with the existing zlib path as the reference. Keep the decoder's existing output and window bounds. No separate issue was filed.
Contract and boundary impact
The shared ELF compressed-section decoder used by debug link and note inspection. The malformed path retains its existing inflation work accounting. This PR fits the existing scope. No new provider, target execution, product packaging, or installation behavior is introduced.
Evidence and regression coverage
The new case fails on main. With the fix it refuses the unread byte, and the unmodified frame still succeeds. Node v24.22.1 produced the behavior in the test. Fixtures are synthetic and no separate CLI run was performed.
Validation performed
3fdda4e1aand passed with the fix.npm run check:fastpassed. The push hook was bypassed and the check was run separately because workspace disk space was limited.git diff --checkpassed for this branch.Author readiness
Human owner: @ShuaixinHuang
Before merge
type(scope): outcome.