Skip to content

Commit f8df431

Browse files
only21milclaudemaria-rcks
authored
fix(antigravity): binary file reads return an error, not garbled text (#25292)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 40b4353 commit f8df431

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ describe("AntigravityAdapterV2 client file system", () => {
332332
context("fs/read_text_file"),
333333
);
334334
assert.equal(pasted.content, "pasted");
335+
yield* fileSystem.writeFileString(insidePath, "\uFEFFfirst\né中🙂\nlast");
336+
const sliced = yield* readTextFile(
337+
{ sessionId: "mock-session-1", path: insidePath, line: 2, limit: 1 },
338+
context("fs/read_text_file"),
339+
);
340+
assert.equal(sliced.content, "é中🙂");
341+
yield* fileSystem.writeFileString(insidePath, "inside");
342+
for (const [name, bytes] of [
343+
["image.png", new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])],
344+
["data.bin", new Uint8Array([0x61, 0, 0x62])],
345+
] as const) {
346+
const binaryPath = path.join(workspace, name);
347+
yield* fileSystem.writeFile(binaryPath, bytes);
348+
const binaryRead = yield* readTextFile(
349+
{ sessionId: "mock-session-1", path: binaryPath },
350+
context("fs/read_text_file"),
351+
).pipe(Effect.flip);
352+
assert.propertyVal(binaryRead, "code", -32602, `${name} is refused as binary`);
353+
}
335354

336355
const outsideRead = yield* readTextFile(
337356
{ sessionId: "mock-session-1", path: outsideFile },

‎apps/server/src/provider/acp/AntigravityClientFiles.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,25 @@ export const readAntigravityClientTextFile = Effect.fn("AntigravityClientFiles.r
7878
`File '${input.request.path}' is not a readable text file under ${CLIENT_FILE_MAX_BYTES} bytes.`,
7979
);
8080
}
81-
const text = yield* input.fileSystem
82-
.readFileString(filePath)
81+
const bytes = yield* input.fileSystem
82+
.readFile(filePath)
8383
.pipe(
8484
Effect.mapError(() =>
8585
EffectAcpErrors.AcpRequestError.internalError(`Could not read '${input.request.path}'.`),
8686
),
8787
);
88+
const text = yield* Effect.try({
89+
try: () => new TextDecoder("utf-8", { fatal: true }).decode(bytes),
90+
catch: () =>
91+
EffectAcpErrors.AcpRequestError.invalidParams(
92+
`File '${input.request.path}' is not a UTF-8 text file.`,
93+
),
94+
});
95+
if (text.includes("\0")) {
96+
return yield* EffectAcpErrors.AcpRequestError.invalidParams(
97+
`File '${input.request.path}' contains binary data.`,
98+
);
99+
}
88100
const line = input.request.line ?? undefined;
89101
const limit = input.request.limit ?? undefined;
90102
if (line === undefined && limit === undefined) {

0 commit comments

Comments
 (0)