fix: harden sessions_spawn attachment schema landing (#33648) (thanks @anisoptera)

This commit is contained in:
Ayaan Zaidi
2026-03-04 10:05:14 +05:30
committed by Ayaan Zaidi
parent 965ce31d84
commit 6962d2d79f
3 changed files with 26 additions and 2 deletions

View File

@@ -611,13 +611,14 @@ export async function spawnSubagentDirect(
}
buf = strictBuf;
} else {
buf = Buffer.from(contentVal, "utf8");
const estimatedBytes = buf.byteLength;
// Avoid allocating oversized UTF-8 buffers before enforcing file limits.
const estimatedBytes = Buffer.byteLength(contentVal, "utf8");
if (estimatedBytes > maxFileBytes) {
fail(
`attachments_file_bytes_exceeded (name=${name} bytes=${estimatedBytes} maxFileBytes=${maxFileBytes})`,
);
}
buf = Buffer.from(contentVal, "utf8");
}
const bytes = buf.byteLength;