fix(hooks): bound hook workspace manifest and HOOK.md reads#101472
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 6:11 AM ET / 10:11 UTC. Summary PR surface: Source +13, Tests +94. Total +107 across 2 files. Reproducibility: yes. A workspace containing a Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the canonical 1 MiB pinned-descriptor limit with warning-and-skip semantics once exact-head checks complete, preserving continued discovery and the plain Do we have a high-confidence way to reproduce the issue? Yes. A workspace containing a Is this the best way to solve the issue? Yes. Reusing the canonical descriptor-pinned bounded reader at the existing workspace discovery boundary is narrower and safer than adding another reader or changing hook resolution policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4880231ff710. Label changesLabel justifications:
Evidence reviewedPR surface: Source +13, Tests +94. Total +107 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (29 earlier review cycles; latest 8 shown)
|
9e067e4 to
391be6d
Compare
391be6d to
661237e
Compare
|
@clawsweeper re-review\n\nI added real behavior proof to the PR body, including the local test command and output that exercises the oversized-file rejection path. |
661237e to
9f9bd82
Compare
|
@clawsweeper re-review Added real behavior proof that exercises Ran a standalone Node script importing the real source function and loading a temp workspace containing:
Output showed only The bounded read happens before JSON parsing, frontmatter parsing, or handler resolution, so no downstream processing is reached for oversized metadata. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Addressed the [P2] finding: replaced the unbounded |
|
🦞🧹 I asked ClawSweeper to review this item again. |
4734252 to
c596612
Compare
|
Rebased onto current `upstream/main` (force-pushed as `fa55a3207bd`) and re-ran the hook workspace focused tests: node scripts/run-vitest.mjs src/hooks/workspace.test.ts --runResult: 12/12 passed. The previous `checks-node-compact-small-1` failure was a flaky TUI PTY e2e timeout unrelated to this change; fresh CI is now running on the rebased head. Please re-review and update the contributor status label when CI finishes. |
|
Rebased onto the latest `upstream/main` where the `check-test-types` declaration issue was fixed (force-pushed as `8d026076b4f`). Local verification:
|
ClawSweeper review noted that openRootFileSync validates stat size before returning the fd, but the subsequent fs.readFileSync of the fd was unbounded. A file that grows after validation could still OOM workspace discovery. Replace the full fd read with a chunked bounded reader that throws once maxBytes is exceeded, and add regression coverage for the overflow case.
ClawSweeper review required the maintainer-selected oversized-metadata diagnostic contract: warn and skip. readRootFileUtf8 now catches the RangeError from the canonical readFileDescriptorBoundedSync helper and emits one warning per oversized package.json/HOOK.md identifying the path and the byte limit, while discovery continues for other hooks. The redundant open-time maxBytes stat check is removed so the shared bounded reader is the single owner of the byte cap; overflow always surfaces as RangeError, keeping the warning accurate for both static oversized files and post-open growth. Add focused tests: warning content for both oversized surfaces, continued discovery alongside an oversized hook, exact-limit acceptance, and the plain-hook fallback when a package manifest is oversized.
|
Merged via squash.
|
What Problem This Solves
Workspace hook discovery read
package.jsonandHOOK.mdthrough validated file descriptors without bounding the allocated content. A malicious or runaway hook descriptor could therefore exhaust memory during discovery.Why This Change Was Made
Both files are small hook metadata. Discovery now reads each already-pinned descriptor through the shared bounded reader with the maintainer-approved 1 MiB limit. This keeps the existing path, symlink, hardlink, and descriptor-identity checks while also bounding files that grow after open.
User Impact
Oversized hook metadata is warned about and skipped. Discovery continues for other hooks, and an oversized package manifest still falls back to a plain
HOOK.mdin the same directory.Maintainer Changes
main.Evidence
node scripts/run-vitest.mjs src/hooks/workspace.test.ts— 10 tests passed.oxlint src/hooks/workspace.ts src/hooks/workspace.test.ts— passed.git diff --check origin/main...HEAD— passed.Co-authored-by: 陈宪彪0668000387 [email protected]