Skip to content

fix(electron): complete short fuse image reads - #6194

Closed
mertkayacs wants to merge 2 commits into
morluto:mainfrom
mertkayacs:fix/electron-fuse-short-reads
Closed

mertkayacs wants to merge 2 commits into
morluto:mainfrom
mertkayacs:fix/electron-fuse-short-reads

Conversation

@mertkayacs

@mertkayacs mertkayacs commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Complete legal positive short reads while inspecting Electron fuse images. This prevents unchanged images from being reported as changed when one positional file read returns fewer bytes than requested.

No linked issue: I found this while reading the Electron fuse reader, and the change is small enough that the evidence fits here.

Problem and expected behavior

FileHandle.read reports the number of bytes actually read, and a positive result can be smaller than the requested length. The Electron fuse reader currently requires every individual read to fill the requested range. A valid unchanged image therefore raises RegularFileChangedError after a positive short read.

The reader should retry from the returned position until the requested range is complete. A zero-byte read before the admitted file extent should continue to signal truncation or mutation.

Change and scope

Add one exact-read helper at the file-reading boundary and use it for container identification, chunk scanning, and fuse-wire reads. The helper preserves positional reads, checks cancellation between attempts, and keeps the existing zero-byte failure.

Add a regression that uses a real file descriptor while limiting each native read request to three bytes. The test verifies that the complete Mach-O fuse report is recovered through multiple reads.

This is limited to Electron fuse image reads. It does not change target admission, format parsing, result schemas, or file mutation authority.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ElectronFuseReader owns exact file-range reads. The earliest changed stage is file I/O before container identification, hashing, and sentinel parsing.
  • Contribution scope fit and linked maintainer decision: Routine correctness fix within the existing static artifact inspection boundary. No advance maintainer scope decision is required.
  • CLI and MCP/tool-catalog contract: No schema or command change. Existing Electron fuse inspection succeeds for legal positive short reads instead of returning a file-changed error.
  • Provider, bridge, target-format, or platform compatibility: Built-in Electron fuse inspection only. Mach-O, ELF, and PE parsing contracts are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: Artifact bytes, SHA-256 calculation, selected path, resolved path, and fuse evidence are unchanged. The reader now consumes the entire admitted range before interpreting it.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): The existing caller-selected, read-only regular file and FileHandle lifecycle are unchanged. Node's documented FileHandle.read byte count controls progress. Cancellation is checked before each retry.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): 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: Added completes short positional reads before interpreting the image in src/electron/ElectronFuseProvider.test.ts. It limits native reads to three bytes and asserts the complete Mach-O fuse result.
  • Base reproduction or other evidence: On base revision 22c4b528d2e06bee8c5f5034f5b184fec0954724, the new test failed with RegularFileChangedError; 1 test failed and 27 passed. Node documents that end of file on an unchanged file is indicated by a zero-byte read, so a positive short read must not be treated as end of file or mutation.
  • User-visible CLI/MCP output (if applicable): No separate CLI or MCP workflow ran. The production reader returned a normal report through the source test after the fix.
  • Remaining proof gaps: The short-read condition was injected around a real local descriptor rather than observed from a specific filesystem. No non-Linux platform or CLI/MCP end-to-end workflow ran.

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/electron/ElectronFuseProvider.test.ts on the test-only commit: failed as expected with 1 failed and 27 passed.
  • npm run test:focused -- src/electron/ElectronFuseProvider.test.ts: 1 file passed, 28 tests passed.
  • npm run test:local -- src/electron/ElectronFuseArchitecture.test.ts src/electron/ElectronFuseCleanup.test.ts src/electron/ElectronFuseCompletion.test.ts src/electron/ElectronFuseProvider.test.ts src/electron/ElectronFuseReaderCleanup.test.ts: 5 files passed, 80 tests passed.
  • npm run check:fast: typecheck and lint both passed.
  • git diff upstream/main...HEAD --check: passed with no output.

Compatibility, safety, and release

  • Breaking changes or migration steps: None.
  • Real Hopper/Ghidra, browser, or OS coverage: Not applicable to providers and browser workflows. Verified on Node.js 24.18.0 (the pinned version) and 22.22.3, Linux x86_64 only.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Read-only local file authority and existing size bounds are unchanged. The loop advances only on positive reads, stops on zero, and checks cancellation between reads. No network, process, mutation, or credential boundary is added.

Author readiness

Human owner: @mertkayacs

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

@mertkayacs
mertkayacs marked this pull request as ready for review October 25, 2026 13:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T14:08:31.228895Z 2509303 Draft marked ready
ℹ️ 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 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects the bounded Electron fuse inspection workflow.

The PR appears safe to merge, with non-blocking improvements to the short-read tests.

Findings

  1. P2 Wrong fuse bytes can pass ▶
  2. P2 Retry stop cases lack tests ▶
Fix with agent prompt
### Issue 1
src/electron/ElectronFuseProvider.test.ts:287-301
The short-read test checks `complete`, but not the recovered fuse bytes or `sha256`. Since `complete` only compares lengths, incorrect fuse values could still pass. Compare the short-read report with a normal-read report, or assert the expected `raw_byte` values and digest.

### Issue 2
src/electron/ElectronFuseReader.ts:465-474
The new loop has no regression for a positive short read followed by zero bytes, or for cancellation between retries. Existing cancellation tests cover later cleanup stages, so these paths could break unnoticed. Add both cases and check that the reader stops, reports the expected error, and closes the descriptor.

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.

Summary

The PR adds one helper that completes positive short reads before the Electron fuse reader interprets the bytes.

  • Electron fuse inspection completes each requested file range before reading it.

Source review only; no tests were run during this review. Current supersession status could not be confirmed.

Reviews (1) · Last reviewed commit: "fix(electron): complete short fuse image..." · Reviewed by Greptile

Comment on lines +287 to +301
expect(report).toMatchObject({
format: "mach-o",
bytes: image.bytes.length,
slices: [
{
sentinel_count: 1,
sentinels: [
{
sentinel_offset: image.sentinelOffset,
complete: true,
},
],
},
],
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Wrong fuse bytes can pass

The short-read test checks complete, but not the recovered fuse bytes or sha256. Since complete only compares lengths, incorrect fuse values could still pass. Compare the short-read report with a normal-read report, or assert the expected raw_byte values and digest.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/electron/ElectronFuseProvider.test.ts
Line: 287-301

Comment:
**Wrong fuse bytes can pass**

The short-read test checks `complete`, but not the recovered fuse bytes or `sha256`. Since `complete` only compares lengths, incorrect fuse values could still pass. Compare the short-read report with a normal-read report, or assert the expected `raw_byte` values and digest.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +465 to +474
while (completed < length) {
assertArtifactReadActive(signal);
const read = await handle.read(
buffer,
offset + completed,
length - completed,
position + completed,
);
if (read.bytesRead === 0) throw new RegularFileChangedError(path);
completed += read.bytesRead;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Retry stop cases lack tests

The new loop has no regression for a positive short read followed by zero bytes, or for cancellation between retries. Existing cancellation tests cover later cleanup stages, so these paths could break unnoticed. Add both cases and check that the reader stops, reports the expected error, and closes the descriptor.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/electron/ElectronFuseReader.ts
Line: 465-474

Comment:
**Retry stop cases lack tests**

The new loop has no regression for a positive short read followed by zero bytes, or for cancellation between retries. Existing cancellation tests cover later cleanup stages, so these paths could break unnoticed. Add both cases and check that the reader stops, reports the expected error, and closes the descriptor.

---

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!

@morluto

morluto commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thank you for the clear short-read report and regression. This behavior is now covered structurally on main by commit d54f5b0: container and fuse-wire reads use the shared positional-range reader, while the scan advances on positive partial reads; premature EOF still reports a changed file. I am closing this as superseded. If the descriptor-limited Electron regression here catches a case the shared coverage misses, please feel free to reopen or propose it as a focused test follow-up.

@morluto morluto closed this Oct 26, 2026
@morluto morluto added bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants