Repository navigation
fix(pe): accept WIN_CERTIFICATE padding counted in dwLength - #6721
Conversation
Codex Review SummaryThis 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 PR appears safe to merge; no new actionable issues were found. SummarySeparates encoded CMS bytes from counted
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Read type-2 WIN_CERTIFICATE entry"] --> B["Read ASN.1 root once"]
B --> C{"No trailing bytes, or exact zero alignment gap?"}
C -->|No| D["Reject entry"]
C -->|Yes| E["Decode CMS from the same root"]
E --> F["Report CMS range and hash without padding"]
F --> G["Keep artifact identity and declared entry range"]
Reviews (4) · Last reviewed commit: "style: format files inherited from main ..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e850dcfaa0
ℹ️ 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.
AI-assisted review found no correctness issue in the counted-padding fix. The certificate boundary accepts only zero bytes in the exact eight-byte alignment gap, retains dwLength/original entry ranges, excludes padding from CMS hashes, and reuses the validated ASN.1 root without weakening ContentInfo consumption checks. The earlier duplicate-decode concern is substantively addressed.
An independent pinned-Node source probe passed 68 PE32/PE32+, padding 0–7, BER and malformed controls; restoring the base parser reproduced the trailing-data failure. This is production-source validation, not compiled CLI/MCP, real-world signed-PE or cryptographic verification.
I authorized exact-head CI/title execution. Approval requires the outstanding required workflow results to complete green; admission of the run is not a pass. No blind rerun of an active job or duplicate inline thread was added.
Review follow-up
CI follow-up: attempt 2 of run 39958633063 completed red. Test shard (2/8), job 120446903563, fails referenceSourceQueuedDirectories.test.ts with expected retained entries versus []. That path is outside the PE certificate diff. Approval remains withheld; no clean-base reproduction or transient cause is established and no further blind retry is planned.
…tificate-dwlength-padding # Conflicts: # src/native/pe/PeCertificateParser.ts
CassieFox23
left a comment
There was a problem hiding this comment.
TL;DR: Main still rejects some PE certificate entries (issue #6694). In them, dwLength counts the zero alignment padding. This PR stops the PKCS#7 payload at its ASN.1 root and accepts only zero bytes that fill the exact 8-byte gap. I found no logic bug. CI has not run tests on the current head, so there is no green run yet.
Findings
Should fix
- The body does not keep the repo template as written. Please restore the template text. What changed:
- The paragraph after "Follow the contribution scope" is gone. It began with "Unresolved scope, authority, side effects ...". It ended with "Maintainers can help resolve open questions". The PR added its own paragraph above the link instead.
- The "Expected effects" line lost both of its sentences. The template says to check known effects, and that unchecked items do not establish absence.
- Three labels lost words. Two of them lost "(if applicable)". One is "Target selection ... cleanup details". The other is "User-visible CLI/MCP output". "Generated metadata" lost its
docs/public/product-catalog.jsonnote and the line about CI building the catalogs andskills/. - All other headings and checkboxes are present. The author readiness boxes are checked.
Worth a look
- CI has not tested this head. On dbc31e2, the
CIandPR titleruns areaction_required, so no test ran. The last real run was on the earlier head f4cdff4: run 39958633063, attempt 2.Test shard (2/8)failed ontraverses directories lstat-observed before their parent enumeration failedintests/boundary/filesystem/referenceSourceQueuedDirectories.test.ts(expected[]to deeply equal an array). The PR does not touch that file. baron already noted this. I do not know the cause. The same test passed in four main push runs where I read its line. The runs are:- 39993628893
- 39991625683
- 39987706965
- 39966102793
- Main has a red test in this area that is not this PR's. Main's push runs fail
tests/acceptance/peCertificatesCli.test.ts > rejects TeletexString names without returning corrupted identity text. The head holds the same test and the TeletexString code that came in with the merge of 5f702dd. No run on this head has reached that test, so I cannot say it fails here. - The Codex thread 4359783912 about decoding the tree twice is still open. The follow-up commit f4cdff4 answers it:
parsePkcs7SignedDatanow takes the decoded root and the parser passes it in. The Greptile thread on the same point is resolved. Resolving the Codex one would tidy the PR. docs/pe-certificates.mddoes not mention counted padding. Its "Limits and failures" section lists what fails. The issue says the failure profile does not exclude ordinary padding. The body ticks "Owning docs ... updated" but no doc changed. One sentence would close the gap: padding that fills the 8-byte gap and is all zero is accepted, anything else fails.- The new accept test builds its fixture with the default signedData payload, so it covers one gap size. I did not work out which. baron ran a 0 to 7 byte probe, but that probe is not in the repo. A loop over the possible gap sizes in the test would pin the check
8 + entryPayload.length !== alignedLength(lines 124-133). A two-entry table with counted padding would also pin the step to the next entry. That step,align8(at + length), is unchanged. - Trailing data that is not padding now gives a different message. It used to be
PKCS#7 signedData is malformed: ContentInfo has trailing data.Now it isWIN_CERTIFICATE has invalid PKCS#7 alignment padding.Both go through the samefailhelper, so the failure kind is the same by my reading. A search ofsrc,testsanddocsat the head for "trailing data" finds that old string only inPeCertificateAsn1.ts.
Nits
- Line 183,
if (cause instanceof ArtifactReaderFailure) throw cause;, changes nothing.PeCertificateAsn1FailureandArtifactReaderFailureboth extendError. Neither extends the other. So the last line of thecatchalready rethrows the padding failure. It can go.
Looks good
- Main (ef475fc) still has the bug. The parser slices all
dwLength - 8bytes and the ASN.1 reader fails when the root does not end at the buffer end. Nothing insrc/native/pe/PeCertificateParser.tshas changed on main since the merge base 5f702dd. - The padding rule is tight. The payload ends at
root.end. Padding is accepted only when two things hold. The whole entry (header plus payload) is exactlyalign8(8 + root.end)long. Every extra byte is zero. A full extra 8 zero bytes fails, and so does one nonzero byte. Theextratest case covers the first, thenonzeroone the second. - The reported facts stay honest.
lengthand the entry location keepdwLength, while the payload range and SHA-256 cover only the encoded CMS bytes. The test checks the artifact digest and size against the original bytes. - The strict trailing-data check stays for every other caller of
parsePkcs7SignedData. BER indefinite-length input keeps a test. - The merge of main into the branch is clean. The diff against main is four files in
src/native/pe, 77 added and 7 removed lines (compare API). - The body is clear on what it did not run: no full suite, no real PE file, no CLI or MCP check of the counted-padding case.
- baron's review found no correctness issue, ran an external 68-case probe, and noted the CI result. I agree on the logic and did not repeat their points.
- No other open PR fixes #6694. The same author's #6711 has the same title and was closed at 12:42 UTC today. I did not read why.
Not run
- No checkout, no build, no tests, no formatter, no PE file parsed.
- I did not read the full test file. I read the two new tests, the titles of the rest, and the fixture builder.
- I did not check the body's timing numbers or its claim that the new tests fail on the base.
Thanks, Deepak-Kambala, for the fix and the follow-up commit. Thanks, coygeek, for the careful repro in #6694.
Test setup
🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊
Summary
Fixes #6694.
inspect-pe-certificatesnow accepts valid PE32 and PE32+ certificate entries whenWIN_CERTIFICATE.dwLengthincludes the required zero-filled alignment padding.Problem and expected behavior
When
dwLengthincluded alignment padding, the parser treated alldwLength - 8bytes as CMS data. The padding then appeared as trailing ASN.1 data, and structural inspection failed. The encoded CMS payload should end at its ASN.1 root boundary; only format-permitted alignment padding may follow it.Change and scope
Use the ASN.1 root end offset to bound the encoded CMS payload. Accept trailing bytes only when they are zero-filled and exactly the padding needed to align the full certificate entry. Preserve the original artifact bytes and digest,
dwLength, and entry range; report the CMS payload range and hash without alignment padding. Malformed CMS and other trailing data remain rejected. Reuse main’s decoded-root CMS interface, with trailing-byte validation owned by the PE entry parser. Document payload ranges and hashes. Cover every alignment gap and consecutive entries. Refresh the two stale test expectations identified in review for TeletexString compatibility and retained filesystem diagnostics.This is a routine static PE-format inspection fix within the existing contribution scope; no maintainer scope decision is required. No CLI/MCP contract or generated metadata changes are included. Structural inspection does not verify cryptographic signatures.
Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
PeCertificateParser, at PE certificate-table entry parsing.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
For evidence-bearing changes:
Validation performed
Current merge with main (
960b74258), Node.js 24.22.1:npm run test:local -- src/native/pe/PeCertificateParser.test.ts src/domain/native/peCertificates.test.ts src/application/binaryDiagnostics/PeCertificatesService.test.ts— 38 passed.npm run test:focused -- tests/acceptance/peCertificatesCli.test.ts tests/boundary/mcp/peCertificatesMcp.test.ts tests/boundary/filesystem/peCertificates.test.ts tests/boundary/filesystem/referenceSourceQueuedDirectories.test.ts— 10 passed after updating the two stale assertions noted in review.npm run check:fast— typecheck and lint passed.f538cd2aa: formatted six files inherited from main after CI reportedformat:checkfailures.npm run check:ci:fast— passed locally, including formatting, typecheck, compilation, lint and module boundaries.git diff --check— passed.Compatibility, safety, and release
Author readiness
Human owner: @Deepak-Kambala
Before merge
type(scope): outcome.