fix(browser-transfer): report oversized uploads as LIMIT_EXCEEDED (R-1.4)
snapshotRequest() threw a TypeError when the source exceeded maxFileBytes or maxPartCount, and upload() mapped every snapshot error to INVALID_INPUT. The LIMIT_EXCEEDED branch in executeUpload() re-checked the same policy and could never run, so a 6 GB file was reported as invalid input. snapshotRequest() now validates only request shape; executeUpload() owns the size check and returns LIMIT_EXCEEDED before any control-plane call. Verified: RED "reports a source over maxFileBytes as LIMIT_EXCEEDED" (tests/unit/resumable-upload-runtime.test.ts) received INVALID_INPUT before the fix and passes after. A valid policy already bounds the part count by maxFileBytes, so the maxPartCount branch is covered by the same check. Gates: check:architecture, check:types:app, check:types:test, lint, test:component pass; test:unit passes except removal-fixture.test.ts, which needs untracked artifacts/release/* absent from a fresh worktree (unrelated). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3f2cd87f6f
commit
961f124ecd
@@ -216,7 +216,7 @@ export function createResumableUploadRuntime<Capability>(
|
||||
}
|
||||
let request: UploadRequestSnapshot;
|
||||
try {
|
||||
request = snapshotRequest(input, dependencies.policy);
|
||||
request = snapshotRequest(input);
|
||||
} catch {
|
||||
return browserDataFailure("INVALID_INPUT", "UPLOAD_SESSION");
|
||||
}
|
||||
@@ -1742,7 +1742,6 @@ function quarantinedOutcome(
|
||||
|
||||
function snapshotRequest(
|
||||
input: ResumableUploadRequest,
|
||||
policy: ResumableUploadRuntimePolicy,
|
||||
): UploadRequestSnapshot {
|
||||
if (
|
||||
!input ||
|
||||
@@ -1759,14 +1758,8 @@ function snapshotRequest(
|
||||
) {
|
||||
throw new TypeError("Upload request is invalid.");
|
||||
}
|
||||
// R-1.4. Size limits are checked by executeUpload as LIMIT_EXCEEDED.
|
||||
const source = snapshotUploadSource(input.source);
|
||||
if (
|
||||
source.byteLength > policy.maxFileBytes ||
|
||||
Math.ceil(source.byteLength / policy.partSizeBytes) >
|
||||
policy.maxPartCount
|
||||
) {
|
||||
throw new TypeError("Upload request exceeds policy.");
|
||||
}
|
||||
return Object.freeze({
|
||||
uploadKey: input.uploadKey,
|
||||
purpose: input.purpose,
|
||||
|
||||
@@ -215,6 +215,36 @@ describe("production resumable upload runtime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// R-1.4. The size check used to throw inside request validation and surface
|
||||
// as INVALID_INPUT; a file over the policy limit is LIMIT_EXCEEDED.
|
||||
it("reports a source over maxFileBytes as LIMIT_EXCEEDED", async () => {
|
||||
const harness = createControlHarness();
|
||||
const createSession = vi.spyOn(harness.control, "createSession");
|
||||
const runtime = createResumableUploadRuntime({
|
||||
controlPlane: harness.control,
|
||||
partExecutor: executorFor(harness),
|
||||
checkpoints: new MemoryCheckpointStore(),
|
||||
mutationLock: noContentionLock,
|
||||
crypto,
|
||||
// A valid policy already bounds the part count by maxFileBytes.
|
||||
policy: runtimePolicy({ maxFileBytes: 4 }),
|
||||
now: () => 1_000,
|
||||
sleep: async () => {},
|
||||
});
|
||||
const result = await runtime.upload({
|
||||
uploadKey: "upload_key_too_large",
|
||||
purpose: "attachment",
|
||||
mediaType: "application/octet-stream",
|
||||
source: byteStreamSource(new Uint8Array([1, 2, 3, 4, 5])),
|
||||
signal: activeSignal,
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "LIMIT_EXCEEDED" },
|
||||
});
|
||||
expect(createSession).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("fails closed when server list-parts disagrees with the current source manifest", async () => {
|
||||
const checkpoints = new MemoryCheckpointStore();
|
||||
const harness = createControlHarness({
|
||||
|
||||
Reference in New Issue
Block a user