Skip whole reads of binaries over the blob limit on disk intake
of shared·codex-capacity-chair··Not checked
Version 182 · Files at version 183
3 files, 22 lines added, 6 removed.
--- a/server/src/ingest.ts
+++ b/server/src/ingest.ts
@@ -109,6 +109,7 @@
109109 maxPackBytes: number; 110110 maxObjectBytes: number; 111111 maxDecodedBytes?: number; 112+ maxBinaryBytes?: number; 112113 http?: HttpClient; 113114 retainFileChunks?: RetainFileChunks; @@ -165,6 +166,7 @@
167168 disk?.retainFileChunks, 169+ disk?.maxBinaryBytes, @@ -192,6 +194,7 @@
192194 cache: object = {}, 193195 intake?: GitDiskIntake, 194196 retainFileChunks?: RetainFileChunks, 197+ maxBinaryBytes?: number, 196199 files: Record<string, string>; @@ -233,6 +236,12 @@
233236 modes[path] = { exec: mode === EXEC, link: null }; 239+ if (storeBlob && maxBinaryBytes !== undefined && stored.byteLength > maxBinaryBytes) { 241+ const kept = oldBlob(path); 242+ if (kept) blobs[path] = kept; 237246 const bytes = await entry.content(); 238247 if (!bytes) return true; --- a/server/src/project-object.ts
+++ b/server/src/project-object.ts
@@ -577,6 +577,7 @@
577577 maxPackBytes: GIT_PACK_MAX_BYTES, 578578 maxObjectBytes: GIT_OBJECT_MAX_BYTES, 579579 maxDecodedBytes: GIT_DECODED_MAX_BYTES, 580+ maxBinaryBytes: BLOB_MAX, 580581 retainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid), --- a/server/test/git-disk-clone.test.ts
+++ b/server/test/git-disk-clone.test.ts
@@ -15,13 +15,14 @@
1515 return Buffer.concat([Buffer.from((body.length + 4).toString(16).padStart(4, "0")), body]); 18−for (const mode of ["success", "limit", "fatal", "server-intake", "text-intake"])
18+for (const mode of ["success", "limit", "fatal", "server-intake", "text-intake", "binary-limit"]) 1919 test(`actual disk clone handles ${mode}`, async (t) => { 2020 const rejectPack = mode === "limit"; 2121 const source = new MemoryFS(), 2323 await git.init({ fs: source, dir, defaultBranch: "main" }); 2424 const blob = mode === "text-intake" ? Buffer.from("x".repeat(16383) + "🚀é中".repeat(20000)) : randomBytes(400000); 25+ if (mode === "binary-limit") blob[0] = 255; 2526 const blobOid = await git.writeBlob({ fs: source, dir, blob }); 2627 const tree = await git.writeTree({ @@ -127,12 +128,12 @@
127128 return write(path, ...args); 130− if (mode === "server-intake" || mode === "text-intake") {
131+ if (mode === "server-intake" || mode === "text-intake" || mode === "binary-limit") { 131132 const trees = new GitIntakeTrees(storage); 132− if (mode === "text-intake") {
133+ if (mode === "text-intake" || mode === "binary-limit") { 133134 const original = GitDiskIntake.prototype.read; 134135 t.mock.method(GitDiskIntake.prototype, "read", function (this: GitDiskIntake, oid: string) { 135− if (oid === blobOid) throw Error("whole text blob read forbidden");
136+ if (oid === blobOid) throw Error("whole blob read forbidden"); 136137 return original.call(this, oid); @@ -148,15 +149,17 @@
150151 async (bytes) => { 152+ assert.notEqual(mode, "binary-limit", "oversized binary must not reach the store"); 151153 assert.deepEqual(Buffer.from(bytes), blob); 152154 return "fixture-blob"; 156+ mode === "binary-limit" ? () => "previous-blob" : undefined, 155− undefined,
158160 maxPackBytes: 2000000, 159161 maxObjectBytes: 1000000, 162+ maxBinaryBytes: mode === "binary-limit" ? 100000 : undefined, 161164 retainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid), @@ -164,7 +167,10 @@
164167 assert.equal(found!.base, 0); 165168 assert.equal(found!.commits.length, 1); 166169 if (mode === "text-intake") assert.equal(found!.commits[0]!.files["large.bin"], blob.toString("utf8")); 167− else assert.equal(found!.commits[0]!.blobs["large.bin"], "fixture-blob");
170+ else if (mode === "binary-limit") { 171+ assert.equal(found!.commits[0]!.blobs["large.bin"], "previous-blob"); 172+ assert.deepEqual(found!.tooBig, ["large.bin"]); 173+ } else assert.equal(found!.commits[0]!.blobs["large.bin"], "fixture-blob"); 169175 for (const table of ["git_pack_spool", "git_pack_resolve", "git_object_meta", "git_object_bytes"]) 170176 assert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0);