fix(browser-transfer): drop the bridge's second copy of each part (Q-6.1-3b)

The multipart-to-presigned bridge copied every part with Uint8Array.from
and the presigned executor then snapshotted the same bytes with slice()
before any await. The executor's snapshot is the one the public port
needs, so the bridge now forwards the part buffer as is. The executor
still re-digests its own copy against the part checksum, so a port that
mutated the buffer would fail closed rather than upload other bytes.
partBufferCopyFactor is left at 4; changing a policy default is a
contract migration.

Verified: the bridge test now asserts the port receives the part buffer
itself (failed before: it got a copy) + all gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 13:32:56 +09:00
co-authored by Claude Opus 5.5
parent 9e2c98272f
commit 1997ce4bbe
2 changed files with 10 additions and 2 deletions
@@ -91,7 +91,9 @@ export function createPresignedUploadPartExecutor(
byteLength: input.part.byteLength,
checksumSha256: input.part.checksumSha256,
idempotencyKey: input.idempotencyKey,
bytes: Uint8Array.from(input.bytes),
// Q-6.1-3b. The presigned port snapshots `bytes` before any await,
// so a second copy here only doubled the per-part buffer.
bytes: input.bytes,
signal: input.signal,
});
} catch {
+7 -1
View File
@@ -1083,8 +1083,10 @@ describe("production resumable upload runtime", () => {
let forwardedUploadBinding = "";
let forwardedSessionId = "";
let forwardedRequestBinding = "";
let forwardedBytes: Uint8Array | undefined;
const port: PresignedUploadPartPort = {
async put(input) {
forwardedBytes = input.bytes;
forwardedUploadBinding = input.uploadBindingSha256;
forwardedSessionId = input.sessionId;
forwardedRequestBinding = input.requestBindingSha256;
@@ -1115,6 +1117,7 @@ describe("production resumable upload runtime", () => {
expectedSha256: "a".repeat(64),
expiresAtEpochMs: 2_000,
} as unknown as PresignedUploadPartCapability;
const partBytes = new Uint8Array([1, 2, 3, 4]);
const result = await executor.uploadPart({
protocol: RESUMABLE_UPLOAD_PROTOCOL,
capability,
@@ -1135,7 +1138,7 @@ describe("production resumable upload runtime", () => {
byteLength: 4,
checksumSha256: "a".repeat(64),
},
bytes: new Uint8Array([1, 2, 3, 4]),
bytes: partBytes,
idempotencyKey: "upload-part-idempotency-01",
signal: activeSignal,
});
@@ -1143,6 +1146,9 @@ describe("production resumable upload runtime", () => {
ok: true,
value: { receiptToken: "etag.response-01" },
});
// Q-6.1-3b. The presigned port snapshots the bytes itself, so the bridge
// forwards the part buffer instead of adding a second copy per attempt.
expect(forwardedBytes).toBe(partBytes);
expect(forwardedUploadBinding).toBe("b".repeat(64));
expect(forwardedSessionId).toBe("session_01");
expect(forwardedRequestBinding).toBe("c".repeat(64));