Repository navigation
fix(pe): accept WIN_CERTIFICATE padding counted in dwLength - #6711
Deepak-Kambala wants to merge 1 commit into
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 change reaches the PE certificate-inspection workflow. The PR appears safe to merge, with a non-blocking opportunity to avoid reading each ASN.1 tree twice. Findings
Fix with agent prompt### Issue 1
src/native/pe/PeCertificateParser.ts:120-130
`readAsn1(entryPayload)` builds the full ASN.1 tree, then `parsePkcs7SignedData(payload)` immediately builds it again. This doubles the tree-reading work for every PKCS#7 entry, including entries without counted padding. Reuse the decoded root through a shared helper, while keeping the strict trailing-data check for standalone callers.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAccepts PE certificate entries whose
Review was based on source inspection; tests were not rerun. Whether this PR is superseded could not be checked because GitHub access was unavailable. Reviews (1) · Last reviewed commit: "fix(pe): accept WIN_CERTIFICATE padding ..." · Reviewed by Greptile |
| const root = readAsn1(entryPayload); | ||
| const paddingBytes = entryPayload.length - root.end; | ||
| const alignedLength = align8(8 + root.end); | ||
| if ( | ||
| paddingBytes !== 0 && | ||
| (8 + entryPayload.length !== alignedLength || | ||
| !entryPayload.subarray(root.end).every((byte) => byte === 0)) | ||
| ) | ||
| fail("WIN_CERTIFICATE has invalid PKCS#7 alignment padding."); | ||
| payload = entryPayload.subarray(0, root.end); | ||
| const parsed = parsePkcs7SignedData(payload); |
There was a problem hiding this comment.
Certificate trees get read twice
readAsn1(entryPayload) builds the full ASN.1 tree, then parsePkcs7SignedData(payload) immediately builds it again. This doubles the tree-reading work for every PKCS#7 entry, including entries without counted padding. Reuse the decoded root through a shared helper, while keeping the strict trailing-data check for standalone callers.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/native/pe/PeCertificateParser.ts
Line: 120-130
Comment:
**Certificate trees get read twice**
`readAsn1(entryPayload)` builds the full ASN.1 tree, then `parsePkcs7SignedData(payload)` immediately builds it again. This doubles the tree-reading work for every PKCS#7 entry, including entries without counted padding. Reuse the decoded root through a shared helper, while keeping the strict trailing-data check for standalone callers.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb2db3021f
ℹ️ 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".
| // WIN_CERTIFICATE to eight bytes. Bound CMS to its encoded ASN.1 root; | ||
| // tolerate only the corresponding alignment bytes, never arbitrary | ||
| // trailing data. | ||
| const root = readAsn1(entryPayload); |
There was a problem hiding this comment.
Parse each PKCS#7 payload only once
For every valid type-2 entry, this call builds the entire BER node tree just to discover root.end, and the immediately following parsePkcs7SignedData(payload) builds the same tree again via readAsn1 in PeCertificateAsn1.ts:562. That doubles ASN.1 traversal and node allocation for normal signatures (up to the 16,384-node budget per entry); pass the decoded root/end into the SignedData decoder or have one API return both parsed data and the consumed length instead.
AGENTS.md reference: AGENTS.md:L27-L29
Useful? React with 👍 / 👎.
inspect-pe-certificatesrejected valid PE32 and PE32+ certificate entries whenWIN_CERTIFICATE.dwLengthincluded the required zero alignment padding. Those bytes were passed to the CMS parser as encoded payload, which rejected them as trailing ASN.1 data.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.Regression coverage checks counted-padding PE32 and PE32+ fixtures, existing controls, invalid trailing bytes, malformed CMS, truncated entries, and length boundaries. It also checks artifact identity and entry/payload ranges and hashes.
Fixes #6694
Verification
npm run check:fast: passed.git diff --check: passed.Provider and artifact coverage
Tests use synthetic PE fixtures; no external provider or real-world PE artifact was verified.
Author readiness
Human owner: