fix(01-review): WR-07 base64ToBlob empty-input shortcut + SW-side empty-segment filter

This commit is contained in:
2026-05-16 10:24:38 +02:00
parent 349ae88a8e
commit e9aae09f6d
3 changed files with 81 additions and 7 deletions

View File

@@ -193,3 +193,44 @@ describe('port serialization (GREEN — pins the eventual fix contract)', () =>
expect(merged.size).not.toBe(75); // the bug is gone in the fixed form.
});
});
describe('binary.ts adversarial input (WR-07 + sweep target #6)', () => {
// These tests exercise the PRODUCTION helpers in src/shared/binary.ts,
// not local re-implementations. They pin the WR-07 + sweep-#6
// defensive contracts:
// 1. Empty-string input → zero-byte Blob (early-return shortcut,
// no atob('') round-trip).
// 2. Invalid base64 input → throws DOMException-like InvalidCharacterError,
// caller is expected to wrap in try/catch.
//
// The empty-segment filter in SW's getVideoBufferFromOffscreen relies
// on (1) so the multi-EBML-header concat output never includes a stray
// zero-byte segment. The error-classification step relies on (2) being
// a regular throw so the per-segment try/catch can drop a single bad
// entry without aborting the whole transfer.
it('base64ToBlob("") returns a zero-byte Blob with the requested MIME', async () => {
const { base64ToBlob } = await import('../../src/shared/binary');
const blob = base64ToBlob('', 'video/webm');
expect(blob).toBeInstanceOf(Blob);
expect(blob.size).toBe(0);
expect(blob.type).toBe('video/webm');
});
it('blobToBase64(emptyBlob) round-trips through base64ToBlob to zero bytes', async () => {
const { blobToBase64, base64ToBlob } = await import('../../src/shared/binary');
const original = new Blob([], { type: 'video/webm' });
const b64 = await blobToBase64(original);
expect(b64).toBe('');
const restored = base64ToBlob(b64, 'video/webm');
expect(restored.size).toBe(0);
});
it('base64ToBlob throws on invalid base64 alphabet (caller wraps with try/catch)', async () => {
const { base64ToBlob } = await import('../../src/shared/binary');
// Characters outside the base64 alphabet — atob throws InvalidCharacterError
// synchronously. The SW caller (getVideoBufferFromOffscreen) has a
// try/catch that drops a single bad segment without aborting the batch.
expect(() => base64ToBlob('!!!not-base64!!!', 'video/webm')).toThrow();
});
});