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

@@ -65,6 +65,17 @@ export async function blobToBase64(blob: Blob): Promise<string> {
* @returns A Blob whose bytes match the original encoded blob exactly.
*/
export function base64ToBlob(b64: string, mimeType: string): Blob {
// WR-07 fix: defensive early-return for empty input. `atob('')` returns
// an empty string and the resulting Blob has size 0 — currently no
// caller filters zero-size segments, which would corrupt the
// concatenated WebM with a stray empty EBML segment. Return an
// explicit empty Blob here so the SW-side filter on
// `segment.data.size > 0` (see src/background/index.ts
// getVideoBufferFromOffscreen) can pre-filter cleanly without an
// extra atob round-trip.
if (b64.length === 0) {
return new Blob([], { type: mimeType });
}
const binary = atob(b64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {