Skip to content

fix(ghidra): read UTF-8 signed language definitions - #2772

Merged
morluto merged 1 commit into
morluto:mainfrom
yasshmittal:fix/ghidra-ldefs-bom
Oct 13, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
yasshmittal:fix/ghidra-ldefs-bom

Conversation

@yasshmittal

Copy link
Copy Markdown
Contributor

Summary

Fixes #2533.

A valid Ghidra .ldefs file that begins with a UTF-8 byte order mark aborted the entire language-catalog read. Profile resolution reads that catalog before admitting REA_GHIDRA_LANGUAGE_ID, so one signed file blocked every configured language override.

Problem and expected behavior

readGhidraLanguageCatalog decoded each file with Buffer#toString("utf8"), which keeps the mark as U+FEFF. The strict XML parser then rejected it as content outside the root element. XML 1.0 section 4.3.3 defines the mark as an encoding signature, not document content, so a signed and an unsigned copy of the same document should produce the same catalog.

Change and scope

Each file is now decoded with TextDecoder, which consumes a leading UTF-8 BOM as part of decoding. The fix sits at the byte-to-text boundary, so parseGhidraLanguageDefinitions keeps its strict behavior. Invalid UTF-8 handling (replacement characters) is unchanged, and malformed XML is still rejected.

Not included: honoring non-UTF-8 encoding declarations (for example UTF-16 documents), which were not supported before this change either.

Contribution scope: an ordinary fix within existing boundaries; no maintainer scope decision applies.

Contract and boundary impact

  • Semantic owner and earliest changed stage: .ldefs byte decoding in src/ghidra/GhidraLanguageCatalog.ts.

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix).

  • CLI and MCP/tool-catalog contract: unchanged.

  • Provider, bridge, target-format, or platform compatibility: Ghidra installations with signed .ldefs files now load their catalog.

  • Evidence, artifact, provenance, or reconstruction contract: unchanged.

  • Target selection, authority, upstream behavior, and cleanup details: no Ghidra launch or project change; read-only file parsing.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated: src/ghidra/GhidraLanguageOverride.test.ts builds an installation containing a BOM-signed definition beside an unsigned sibling module and requires both languages to load in order. The existing malformed-document cases still require rejection.

  • Base reproduction or other evidence: on the base revision the signed file rejects the whole catalog with a parse error naming U+FEFF, as in the issue.

  • User-visible CLI/MCP output: a configured language defined in a signed file is admitted instead of failing as a provider error.

  • Remaining proof gaps: no real Ghidra run; no vendor-shipped signed .ldefs file is known (the issue used a controlled fixture).

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Host: Windows 11, Node.js 24.21.0.

  • npm run test:local -- src/ghidra/GhidraLanguageOverride.test.ts: the new test and all catalog tests pass. Four profile tests in this file (commits the configured language…, records the language default…, keeps header auto-detection…, refuses an undefined compiler spec…) fail identically on the unmodified base revision on Windows; they are unrelated to this change.
  • npm run check: passed.
  • npm run verify:test-discovery: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Windows only; no real Ghidra lane run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: decoding change only; the existing 4 MiB per-file bound is unchanged.

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.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

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 ✅ Completed 2026-10-13T12:11:45.766190Z b9a1398 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 Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

The PR uses TextDecoder to consume a leading UTF-8 BOM before parsing Ghidra language definitions.

  • Ghidra now reads language files that start with a UTF-8 mark.

Reviews (2) · Last reviewed commit: "fix(ghidra): read UTF-8 signed language ..." · Reviewed by Greptile

Buffer#toString kept a leading UTF-8 byte order mark as U+FEFF, so the
strict XML parser rejected a valid .ldefs file as content outside the root
element and aborted the whole language catalog read. XML 1.0 section 4.3.3
defines the mark as an encoding signature; decode with TextDecoder, which
consumes it. Malformed XML is still rejected.

Fixes morluto#2533

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto merged commit ec4f4dd into morluto:main Oct 13, 2026
1 check passed
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks for handling BOM-prefixed Ghidra language files, @yasshmittal. One valid .ldefs file should not block every configured language override. Welcome to REA!

@morluto morluto added the provider: ghidra Analysis provider / engine: ghidra label 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 provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ghidra): UTF-8-marked language definitions abort catalog loading

2 participants