Skip to content

fix(elf): reject unconsumed Zstandard section bytes - #12382

Closed
ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/elf-zstd-section-consumption
Closed

ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/elf-zstd-section-consumption

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The new regression failed on base 3fdda4e1a and passed with the fix.
  • The compressed-section, ELF debug-link and ELF note-parser suites passed all 122 tests.
  • The five independent changes were checked together in a temporary Linux source tree. All 294 focused tests and npm run check:fast passed. The push hook was bypassed and the check was run separately because workspace disk space was limited.
  • git diff --check passed for this branch.

Author readiness

Human owner: @ShuaixinHuang

  • 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.

Before merge

  • 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.

@ShuaixinHuang
ShuaixinHuang marked this pull request as ready for review November 19, 2026 14:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T15:36:34.701518Z 1442080 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 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The code appears safe to merge; no new correctness or security issue was found.

Summary

The shared ELF decoder now rejects Zstandard section bytes that the decoder did not consume, matching the existing zlib check.

  • ELF section readers reject extra bytes after a Zstandard frame.

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

@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: 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".

Comment on lines +165 to +168
if (result.consumedBytes !== payload.length)
return {
state: "malformed",
message: `${subject} has bytes after its ${compression} stream`,

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 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 👍 / 👎.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

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.

@morluto morluto closed this Nov 19, 2026
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants