Skip to content

fix(pe): reject surrogate code units in BMPString names - #7817

Merged
morluto merged 3 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-pe-bmpstring-scalars
Oct 29, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-pe-bmpstring-scalars

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem and outcome

PE certificate BMPString names are currently decoded as unrestricted UTF-16. A lone D800 or DFFF is published as a surrogate, and D800 DC00 is combined into U+10000 even though that character is outside the Basic Multilingual Plane.

Reject surrogate code units at the BMPString decoder, using the existing typed ASN.1 failure and public invalid_request mapping. Rename the private helper to identify its actual UCS-2 owner. This follows the BMPString distinction described in Go's X.509 decoder; that reference is source-derived, not a Go runtime test. Valid BMP characters, literal BOMs, existing UTF-8/UniversalString handling and the decoded-name budget are preserved. No new format, dependency, target execution or cryptographic trust-verification capability is introduced. No separate issue: executable regressions below capture the defect.

Evidence and validation

Executed on Windows, Node 24.22.1 / npm 11.16.0, fixed base 6c895eeb:

  • Before the fix: the complete parser test file had 2 failures / 33 passes; the compiled CLI file had 1 failure / 6 passes. The malformed BMPString surrogate pair was accepted with exit code 0 rather than rejected.
  • npm run test:focused -- src/native/pe/PeCertificateParser.test.ts tests/acceptance/peCertificatesCli.test.ts tests/boundary/mcp/peCertificatesMcp.test.ts — 44/44 passed, including required build tasks. Covers isolated high/low surrogates, valid U+D7FF/U+E000/U+FEFF, existing name budgets and supplementary UniversalString, actual CLI rejection of a surrogate pair, successful CLI reading of the corrected neighboring code units, and existing MCP delivery.
  • CLI refusal remains invalid_request, operation inspect_pe_certificates. The positive control verifies the decoded issuer name through the advertised output schema.
  • The additional command including tests/boundary/filesystem/peCertificates.test.ts was 45 passed / 1 failed: an existing test hit Windows EPERM while creating a file symlink, before constructing the service or reaching parsing. This extra command is not reported as green; its assertions were not changed or skipped.
  • npm run check:fast — typecheck/lint 2/2 passed. Normal precommit and prepush passed on the final commit; working tree clean.
  • npm run check — not fully green: three of six tasks completed before ordinary Knip's sole unchanged HexRecordRegionMetadata error (src/domain/artifactFormatMetadata.ts:200). Temporarily restored all three changed files to exact clean 6c895eeb, reproduced the same sole diagnostic, then restored every working byte in finally. Later architecture/production-Knip/typed-lint stages did not execute.

Inputs are synthetic encoded certificates, with real local production parsers and compiled CLI/MCP adapters. No external certificate verifier or signature-trust validation was run or claimed. Hosted CI is pending for this new head.

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-28T14:55:37.463745Z b361808 PR opened
ℹ️ 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 Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

Rejects surrogate code units in PE certificate BMPString names at the shared decoder.

  • BMPString certificate names reject surrogate code units.

Reviews (2) · Last reviewed commit: "chore: preserve base browser imports" · Reviewed by Greptile

@morluto
morluto merged commit 3a46047 into morluto:main Oct 29, 2026
4 checks passed
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 23, 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