Skip to content

fix(android-ota): require complete REPLACE_ZSTD input consumption - #12383

Closed
ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/android-ota-zstd-encoded-extent
Closed

ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/android-ota-zstd-encoded-extent

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An Android OTA REPLACE_ZSTD operation can contain a byte beyond the compressed frame. On main reconstruction succeeded despite not consuming that byte. Both the operation digest and the partition digest matched the values declared in the fixture, since they cover different inputs.

Change and scope

Compare the decompressor's consumed byte count with the admitted operation data length before writing destination extents. Report a malformed operation when encoded bytes remain. Keep the existing output ceiling and digest checks. No separate issue was filed.

Contract and boundary impact

Android OTA partition reconstruction. Changes the result for a malformed REPLACE_ZSTD input and preserves valid reconstruction and coverage semantics. This PR fits the existing scope. No new provider, target execution, product packaging, or installation behavior is introduced.

Evidence and regression coverage

The new fixture reconstructs successfully on main and fails as malformed after the patch. The existing valid REPLACE_ZSTD control still reconstructs the expected bytes. Inputs are synthetic. No vendor OTA payload or separate CLI run was exercised.

Validation performed

  • The new regression failed on base 3fdda4e1a and passed with the fix.
  • The OTA parser and artifact-reader suites passed all 50 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:52
@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:06.332633Z c129036 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] This PR appears safe to merge; no blocking issues were found.

Summary

This PR rejects REPLACE_ZSTD operation data that the decompressor leaves unread, even when both declared hashes match.

  • Android OTA reconstruction rejects extra bytes after a Zstandard stream.

No actionable issues found. A direct Node.js check confirmed that the appended byte remains unread while valid compressed input is fully consumed.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/android-ota..." · Reviewed by Greptile

@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks for this. Unread trailing bytes in a REPLACE_ZSTD operation are a real gap. One thing to change before this can land: bytesWritten can't prove exact Zstandard framing on every supported Node version. On Node 22 it stops at the first frame. It rejects valid empty and skippable suffix frames, and it can accept a truncated checksum once the output size matches. On newer Node it can count a partial next-frame magic as consumed. We hit the same wall in #12382 and recorded the design question in #12398. A root-cause fix is to reuse the shared exact-frame decoder from that decision, so ELF sections and OTA operations share one definition of "complete stream". Please hold this until that lands. Then replace the byte-count comparison with the shared helper, and assert a typed malformed reason in the test instead of expect.stringContaining on the message.

@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Superseded by #12416, now merged into main. Android OTA REPLACE_ZSTD now uses the shared exact-frame reader. Its regression rejects unread input while retaining valid concatenated frames, and the consumption check applies independently of the operation hash. Thanks for identifying the OTA case.

@morluto morluto closed this Nov 19, 2026
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior 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