[PR #2772] [MERGED] fix(ghidra): read UTF-8 signed language definitions #5381

Closed
opened 2026-10-31 01:06:12 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2772
Author: @yasshmittal
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/ghidra-ldefs-bom


📝 Commits (1)

  • b9a1398 fix(ghidra): read UTF-8 signed language definitions

📊 Changes

2 files changed (+26 additions, -1 deletions)

View changed files

📝 src/ghidra/GhidraLanguageCatalog.ts (+3 -1)
📝 src/ghidra/GhidraLanguageOverride.test.ts (+23 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2772 **Author:** [@yasshmittal](https://github.com/yasshmittal) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/ghidra-ldefs-bom` --- ### 📝 Commits (1) - [`b9a1398`](https://github.com/morluto/rea/commit/b9a13989f87c578d2a5a85e3b5d4b6a1e31bdb66) fix(ghidra): read UTF-8 signed language definitions ### 📊 Changes **2 files changed** (+26 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/ghidra/GhidraLanguageCatalog.ts` (+3 -1) 📝 `src/ghidra/GhidraLanguageOverride.test.ts` (+23 -0) </details> ### 📄 Description ## 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. - [x] 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). - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] 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 - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:06:12 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5381
No description provided.