fix(review): reserve header length in buildUnifiedReviewDiff's no-patch branch - #10345
Merged
JSONbored merged 1 commit intoAug 4, 2026
Conversation
…ch branch The patched-file branch of buildUnifiedReviewDiff already reserves the header's length against the remaining budget before appending, but the no-patch branch (binary/too-large files) appended header + suffix unconditionally. A long enough file.path made that header overflow the caller's budget, breaking the same bounded-output invariant the patched branch upholds. Mirror the patched branch's reservation: when header.length + suffix.length would exceed the remaining budget, fall through to the existing truncation-notice-and-break path instead of silently overflowing. The common case (a short path that fits comfortably) renders byte-for-byte as before. Closes JSONbored#10327
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
JSONbored
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
buildUnifiedReviewDiffbuilds a size-bounded unified diff for review. The patched-file branch already reserves the header's length against theremainingbudget before appending:The no-patch branch (binary or too-large files) did not — it appended
header + suffixunconditionally:Because the header interpolates
file.path, a long enough path makesheader.length + suffix.lengthexceed the file'sremainingbudget, and the returned diff overflowsbudget. That breaks the same bounded-output invariant the patched branch upholds — the one asymmetry between the two branches' budget handling.The fix
Mirror the patched branch's reservation in the no-patch branch: check
header.length + suffix.lengthagainstremainingbefore appending, and when it doesn't fit, fall through to the same truncation-notice-and-break path the loop already uses for theremaining < 240case — rather than silently overflowingbudgetor silently dropping the file with no visible signal.Unchanged: the patched-file branch's existing logic, and the common case — a patch-less file whose header+suffix fits comfortably renders byte-for-byte as before (
"${header}(no inline patch — binary or too large)\n\n"). This is an edge-case fix for a longfile.pathonly.Tests (
test/unit/review-diff.test.ts)Extends the existing
#10017budget-invariant suite:budget: 250—remainingclears the< 240floor butheader + suffix(~310) overflows it. Asserts the returned diff's.length <= budget, the truncation notice is present, and the overflowing file was not appended. Fails onmain(returns 308 > 250)."### logo.png (added) +0/-0\n(no inline patch — binary or too large)\n\n"with no truncation notice.Validation
src/review/review-diff.tsis 100% — both arms of the newheader.length + suffix.length > remainingcheck are exercised (lcovBRDAconfirms taken=true and taken=false).npm run typecheckclean;npm run engine-parity:drift-checkpasses (theDIFF_FILE_PRIORITYtwin markers are untouched — 7 pairs agree);npm run dead-exports:check,manifest:drift-check,docs:drift-checkclean.git diff --checkclean; no schema / migration / generated-artifact change.Closes #10327