Repository navigation
fix(config): bound regular-file reads before parsing #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30d525e
fix(config): bound regular-file reads before parsing
luvs01 5a9c154
fix(config): bound integration writes at the read limit
devin-ai-integration[bot] b3f5933
Clean unused snapshots after size refusals
devin-ai-integration[bot] b238f94
Merge current fork dev into bounded reader split
luvs01 72bc394
fix(integrations): discard unused snapshots through their store
luvs01 00ede58
Merge fork dev dc45bb2 into PR #723
luvs01 c0e9e45
perf(config): grow bounded read buffers from the observed size
luvs01 1f01b57
perf(config): preserve initialized bounded read buffers
luvs01 241186b
Merge remote-tracking branch 'fork/dev' into merge723-dev-20261013
luvs01 49802e7
test(lib): keep the oversize assertion when Windows denies symlink cr…
luvs01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from "node:fs"; | ||
|
|
||
| const MAX_BOUNDED_READ_BYTES = 64 * 1024 * 1024; | ||
| const READ_CHUNK_BYTES = 64 * 1024; | ||
|
|
||
| function sameIdentity( | ||
| left: { dev: bigint; ino: bigint }, | ||
| right: { dev: bigint; ino: bigint }, | ||
| ): boolean { | ||
| return left.dev === right.dev && left.ino === right.ino; | ||
| } | ||
|
|
||
| export function readBoundedRegularFileSync(path: string, limit: number): Buffer { | ||
| if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_BOUNDED_READ_BYTES) { | ||
| throw new RangeError("invalid bounded file read limit"); | ||
| } | ||
|
|
||
| const windows = process.platform === "win32"; | ||
| const flags = constants.O_RDONLY | (windows ? 0 : constants.O_NONBLOCK | constants.O_NOFOLLOW); | ||
| const entryBefore = windows ? lstatSync(path, { bigint: true }) : undefined; | ||
| if (entryBefore && (entryBefore.isSymbolicLink() || !entryBefore.isFile())) { | ||
| throw new Error("not a regular file"); | ||
| } | ||
| const fd = openSync(path, flags); | ||
| try { | ||
| const opened = fstatSync(fd, { bigint: true }); | ||
| if (!opened.isFile() || opened.size > BigInt(limit)) throw new Error("file is not bounded regular data"); | ||
| if (entryBefore && (!sameIdentity(entryBefore, opened) || opened.ino === 0n)) { | ||
| throw new Error("file entry changed while opening"); | ||
| } | ||
|
|
||
| // Start near the observed size, but keep probing up to limit + 1 if the file grows. | ||
| let bytes = Buffer.alloc(Number(opened.size) + 1); | ||
| let length = 0; | ||
| while (length < limit + 1) { | ||
| if (length === bytes.length) { | ||
| const capacity = Math.min(limit + 1, Math.max(bytes.length * 2, bytes.length + READ_CHUNK_BYTES)); | ||
| const next = Buffer.alloc(capacity); | ||
| bytes.copy(next, 0, 0, length); | ||
| bytes = next; | ||
| } | ||
| const count = readSync(fd, bytes, length, Math.min(READ_CHUNK_BYTES, bytes.length - length), null); | ||
| if (count === 0) break; | ||
| length += count; | ||
| } | ||
| if (length > limit) throw new Error("file exceeds byte limit"); | ||
|
|
||
| if (entryBefore) { | ||
| const entryAfter = lstatSync(path, { bigint: true }); | ||
| if (entryAfter.isSymbolicLink() || !entryAfter.isFile() || !sameIdentity(opened, entryAfter)) { | ||
| throw new Error("file entry changed while reading"); | ||
| } | ||
| } | ||
| return bytes.subarray(0, length); | ||
| } finally { | ||
| closeSync(fd); | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.