Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

os: reject undersized/truncated image downloads

+27 -4
+27 -4
system/public/aesthetic.computer/disks/os.mjs
··· 930 930 OVEN_ORIGIN + "/os-image" + query, 931 931 OVEN + "/os-image" + query, 932 932 ]; 933 - const MIN_EXPECTED_IMAGE_BYTES = 50 * 1024 * 1024; 933 + const MIN_EXPECTED_EFI_BYTES = 300 * 1024 * 1024; 934 + const MIN_EXPECTED_ISO_BYTES = 200 * 1024 * 1024; 934 935 935 936 let res = null; 936 937 let usedUrl = ""; ··· 962 963 } 963 964 964 965 const len = parseInt(attempt.headers.get("content-length") || "0"); 965 - if (len > 0 && len < MIN_EXPECTED_IMAGE_BYTES) { 966 - console.warn("[os] Rejecting suspiciously small image response:", len, "bytes from", url); 966 + const minExpectedBytes = 967 + servedLayout === "efi" 968 + ? MIN_EXPECTED_EFI_BYTES 969 + : servedLayout === "iso" 970 + ? MIN_EXPECTED_ISO_BYTES 971 + : MIN_EXPECTED_EFI_BYTES; 972 + if (len > 0 && len < minExpectedBytes) { 973 + console.warn("[os] Rejecting suspiciously small image response:", len, "bytes from", url, "layout:", servedLayout || "?"); 967 974 try { attempt.body?.cancel(); } catch (_) {} 968 975 lastErr = "Received suspiciously small image (" + len + " bytes)"; 969 976 continue; ··· 1002 1009 needsPaint(); 1003 1010 1004 1011 const total = chunks.reduce((s, c) => s + c.length, 0); 1005 - if (total < MIN_EXPECTED_IMAGE_BYTES) { 1012 + const servedLayout = (res.headers.get("x-ac-os-layout") || "").toLowerCase(); 1013 + const minExpectedBytes = 1014 + servedLayout === "efi" 1015 + ? MIN_EXPECTED_EFI_BYTES 1016 + : servedLayout === "iso" 1017 + ? MIN_EXPECTED_ISO_BYTES 1018 + : MIN_EXPECTED_EFI_BYTES; 1019 + if (total < minExpectedBytes) { 1006 1020 throw new Error("Image too small (" + (total / 1048576).toFixed(1) + "MB), refusing to save"); 1021 + } 1022 + if (contentLength > 0 && total !== contentLength) { 1023 + throw new Error( 1024 + "Download truncated (" + 1025 + (total / 1048576).toFixed(1) + 1026 + "MB of " + 1027 + (contentLength / 1048576).toFixed(1) + 1028 + "MB)" 1029 + ); 1007 1030 } 1008 1031 const combined = new Uint8Array(total); 1009 1032 let offset = 0;