Repository navigation
fix(electron): complete short fuse image reads - #6194
mertkayacs wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[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. FindingsFix 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.SummaryThe PR adds one helper that completes positive short reads before the Electron fuse reader interprets the bytes.
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 |
| expect(report).toMatchObject({ | ||
| format: "mach-o", | ||
| bytes: image.bytes.length, | ||
| slices: [ | ||
| { | ||
| sentinel_count: 1, | ||
| sentinels: [ | ||
| { | ||
| sentinel_offset: image.sentinelOffset, | ||
| complete: true, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); |
There was a problem hiding this comment.
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.| 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; |
There was a problem hiding this comment.
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!
|
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. |
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.readreports 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 raisesRegularFileChangedErrorafter 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
ElectronFuseReaderowns exact file-range reads. The earliest changed stage is file I/O before container identification, hashing, and sentinel parsing.FileHandlelifecycle are unchanged. Node's documentedFileHandle.readbyte count controls progress. Cancellation is checked before each retry.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): None.Expected effects:
Evidence and regression coverage
completes short positional reads before interpreting the imageinsrc/electron/ElectronFuseProvider.test.ts. It limits native reads to three bytes and asserts the complete Mach-O fuse result.22c4b528d2e06bee8c5f5034f5b184fec0954724, the new test failed withRegularFileChangedError; 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.For evidence-bearing changes:
Validation performed
npm run test:local -- src/electron/ElectronFuseProvider.test.tson 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
Author readiness
Human owner: @mertkayacs
Before merge
type(scope): outcome.