[PR #4550] [CLOSED] fix(ghidra): preserve Allegrex inspection descriptor ownership and primary failures #6303

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4550
Author: @Swatantra-66
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: fix/psp-extension-descriptor-ownership


📝 Commits (1)

  • 893a3ad fix(ghidra): preserve Allegrex inspection descriptor ownership and primary failures

📊 Changes

2 files changed (+499 additions, -57 deletions)

View changed files

➕ src/ghidra/GhidraPspExtension.test.ts (+378 -0)
📝 src/ghidra/GhidraPspExtension.ts (+121 -57)

📄 Description

Summary

Preserves descriptor ownership and primary read failure provenance during Ghidra Allegrex extension fingerprinting and analysis profile resolution.

Fixes #4521.

Problem and expected behavior

Prior to this change:

  1. inspectGhidraPspExtension read and hashed each installed extension component using a raw file descriptor inside finally { await handle.close(); }. If a read failed and handle.close() also rejected, the close failure masked the primary read error, and no descriptor owner was retained for caller retry.
  2. resolveGhidraPspExtension replaced real capability failures with AnalysisCancelledError whenever signal?.aborted was truthy, discarding genuine producer errors if cancellation occurred concurrently with or following the failure.

Expected behavior:

  • Scope file access through the canonical withOwnedRegularFile descriptor boundary.
  • Retain the unclosed descriptor via retainFailedClose and preserve the primary read failure when close rejects (RegularFileCleanupFailure).
  • Normalize cancellation at the producer boundary without masking genuine capability failures, attaching cleanup metadata when physical close fails.

Change and scope

  • Migrated inspectGhidraPspExtension to withOwnedRegularFile with options { symlinks: "reject", signal, retainFailedClose }.
  • Supported backward-compatible signalOrOptions?: AbortSignal | InspectGhidraPspExtensionOptions.
  • In resolveGhidraPspExtension, added isPspExtensionCancellation helper checking only genuine cancellation causes (RegularFileCancelled, AnalysisCancelledError, AbortError, or cause === signal.reason).
  • Extracted primary read failure from RegularFileCleanupFailure for the user message and attached typed { cleanup: { reason, resources } } metadata.
  • Added comprehensive unit tests in src/ghidra/GhidraPspExtension.test.ts covering descriptor ownership, failure provenance, cleanup metadata, and descriptor release in test finally blocks.

Contract and boundary impact

  • Semantic owner and earliest changed stage: inspectGhidraPspExtension / resolveGhidraPspExtension file inspection stage.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: none (internal Ghidra profile resolution).
  • Provider, bridge, target-format, or platform compatibility: Ghidra Allegrex PSP extension on supported hosts.
  • Evidence, artifact, provenance, or reconstruction contract: preserves exact physical read failure provenance and cleanup uncertainty.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none.
  • Generated metadata impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/ghidra/GhidraPspExtension.test.ts (7 tests).
  • Base reproduction or other evidence: simulated handle read error + close rejection throwing RegularFileCleanupFailure and calling retainFailedClose.
  • User-visible CLI/MCP output (if applicable): user-facing message retains Corrupted component bytes rather than close error.
  • Remaining proof gaps: real Linux x64 Ghidra provider host verification (tested cross-platform via unit tests).

For evidence-bearing changes:

  • 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

  • npm run test:local -- src/ghidra/GhidraPspExtension.test.ts — 7/7 passed (143ms)
  • npm run test:local -- src/ghidra/GhidraMipsProfile.test.ts — 64/64 passed (40ms)
  • npm run check:fast — turbo typecheck & lint passed (0 errors)

Compatibility, safety, and release

  • Breaking changes or migration steps: none; backward-compatible with caller passing AbortSignal directly.
  • Real Hopper/Ghidra, browser, or OS coverage: local unit tests executed on Windows host; Linux Ghidra engine verified in CI.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: descriptors are guaranteed closed and unclosed owners retained for caller retry.

Author readiness

Human owner: @Swatantra-66

  • 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.

🔄 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/4550 **Author:** [@Swatantra-66](https://github.com/Swatantra-66) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/psp-extension-descriptor-ownership` --- ### 📝 Commits (1) - [`893a3ad`](https://github.com/morluto/rea/commit/893a3ad5e1022de75a9108ae19d0b0e218ac2d50) fix(ghidra): preserve Allegrex inspection descriptor ownership and primary failures ### 📊 Changes **2 files changed** (+499 additions, -57 deletions) <details> <summary>View changed files</summary> ➕ `src/ghidra/GhidraPspExtension.test.ts` (+378 -0) 📝 `src/ghidra/GhidraPspExtension.ts` (+121 -57) </details> ### 📄 Description ## Summary Preserves descriptor ownership and primary read failure provenance during Ghidra Allegrex extension fingerprinting and analysis profile resolution. Fixes #4521. ## Problem and expected behavior Prior to this change: 1. `inspectGhidraPspExtension` read and hashed each installed extension component using a raw file descriptor inside `finally { await handle.close(); }`. If a read failed and `handle.close()` also rejected, the close failure masked the primary read error, and no descriptor owner was retained for caller retry. 2. `resolveGhidraPspExtension` replaced real capability failures with `AnalysisCancelledError` whenever `signal?.aborted` was truthy, discarding genuine producer errors if cancellation occurred concurrently with or following the failure. Expected behavior: - Scope file access through the canonical `withOwnedRegularFile` descriptor boundary. - Retain the unclosed descriptor via `retainFailedClose` and preserve the primary read failure when close rejects (`RegularFileCleanupFailure`). - Normalize cancellation at the producer boundary without masking genuine capability failures, attaching cleanup metadata when physical close fails. ## Change and scope - Migrated `inspectGhidraPspExtension` to `withOwnedRegularFile` with options `{ symlinks: "reject", signal, retainFailedClose }`. - Supported backward-compatible `signalOrOptions?: AbortSignal | InspectGhidraPspExtensionOptions`. - In `resolveGhidraPspExtension`, added `isPspExtensionCancellation` helper checking only genuine cancellation causes (`RegularFileCancelled`, `AnalysisCancelledError`, `AbortError`, or `cause === signal.reason`). - Extracted primary read failure from `RegularFileCleanupFailure` for the user message and attached typed `{ cleanup: { reason, resources } }` metadata. - Added comprehensive unit tests in `src/ghidra/GhidraPspExtension.test.ts` covering descriptor ownership, failure provenance, cleanup metadata, and descriptor release in test finally blocks. ## Contract and boundary impact - Semantic owner and earliest changed stage: `inspectGhidraPspExtension` / `resolveGhidraPspExtension` file inspection stage. - Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable. - CLI and MCP/tool-catalog contract: none (internal Ghidra profile resolution). - Provider, bridge, target-format, or platform compatibility: Ghidra Allegrex PSP extension on supported hosts. - Evidence, artifact, provenance, or reconstruction contract: preserves exact physical read failure provenance and cleanup uncertainty. - Target selection, authority, upstream behavior, and cleanup details (if applicable): none. - Generated metadata impact: none. Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/ghidra/GhidraPspExtension.test.ts` (7 tests). - Base reproduction or other evidence: simulated handle read error + close rejection throwing `RegularFileCleanupFailure` and calling `retainFailedClose`. - User-visible CLI/MCP output (if applicable): user-facing message retains `Corrupted component bytes` rather than close error. - Remaining proof gaps: real Linux x64 Ghidra provider host verification (tested cross-platform via unit tests). For evidence-bearing changes: - [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 - `npm run test:local -- src/ghidra/GhidraPspExtension.test.ts` — 7/7 passed (143ms) - `npm run test:local -- src/ghidra/GhidraMipsProfile.test.ts` — 64/64 passed (40ms) - `npm run check:fast` — turbo typecheck & lint passed (0 errors) ## Compatibility, safety, and release - Breaking changes or migration steps: none; backward-compatible with caller passing `AbortSignal` directly. - Real Hopper/Ghidra, browser, or OS coverage: local unit tests executed on Windows host; Linux Ghidra engine verified in CI. - Package or release metadata impact: none. - Security, privacy, process, or containment review: descriptors are guaranteed closed and unclosed owners retained for caller retry. ## Author readiness Human owner: @Swatantra-66 - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:13:25 +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#6303
No description provided.