{"record":{"id":"870f67cef3593583","repo":"can1357/oh-my-pi","slug":"invalid-cab-archive-uncompressed-cfdata-sizes-do","errorCode":null,"errorMessage":"Invalid CAB archive: uncompressed CFDATA sizes do not match","messagePattern":"Invalid CAB archive: uncompressed CFDATA sizes do not match","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/cab.ts","lineNumber":186,"sourceCode":"\t\t}\n\t\tif (outputSize < description.requiredSize) {\n\t\t\tthrow new ArchiveError(\"Invalid CAB archive: folder data is shorter than its file table declares\");\n\t\t}\n\n\t\tconst output = new Uint8Array(outputSize);\n\t\tconst lzx = description.method === 3 ? new LzxDecoder(description.parameter) : undefined;\n\t\tposition = 0;\n\t\tlet outputPosition = 0;\n\t\tfor (let block = 0; block < description.blockCount; block++) {\n\t\t\tconst compressed = readUInt16LE(bytes, position + 4);\n\t\t\tconst uncompressed = readUInt16LE(bytes, position + 6);\n\t\t\tconst payloadStart = position + DATA_BLOCK_SIZE + this.#dataReserveSize;\n\t\t\tconst payloadEnd = payloadStart + compressed;\n\t\t\tconst payload = bytes.subarray(payloadStart, payloadEnd);\n\t\t\tlet decoded: Uint8Array;\n\t\t\tif (description.method === 0) {\n\t\t\t\tif (compressed !== uncompressed) {\n\t\t\t\t\tthrow new ArchiveError(\"Invalid CAB archive: uncompressed CFDATA sizes do not match\");\n\t\t\t\t}\n\t\t\t\tdecoded = payload;\n\t\t\t} else if (description.method === 1) {\n\t\t\t\tif (payload.byteLength < 2 || payload[0] !== 0x43 || payload[1] !== 0x4b) {\n\t\t\t\t\tthrow new ArchiveError(\"Invalid CAB archive: MSZIP block is missing its CK signature\");\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst dictionary = output.subarray(Math.max(0, outputPosition - MAX_DATA_OUTPUT), outputPosition);\n\t\t\t\t\tdecoded = new Uint8Array(\n\t\t\t\t\t\tzlib.inflateRawSync(payload.subarray(2), { dictionary, maxOutputLength: uncompressed }),\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new ArchiveError(\n\t\t\t\t\t\t`Invalid CAB archive: MSZIP decompression failed${error instanceof Error ? `: ${error.message}` : \"\"}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdecoded = lzx!.decompressFrame(payload, uncompressed);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/cab.ts#L168-L204","documentation":"Thrown by CabFolder.#decode when the folder's compression method is 0 (none/stored) but a block's cbData (compressed) and cbUncomp (uncompressed) sizes differ. For stored blocks the payload is used verbatim, so the two sizes must be identical; a discrepancy means the block header is inconsistent.","triggerScenarios":"readCab() indexed a cabinet whose CFFOLDER typeA&0x000f equals 0, but a CFDATA block has cbData !== cbUncomp — a malformed header from a buggy writer or bit corruption in the 2 size fields.","commonSituations":"Cabinets produced by non-standard or buggy archivers; corrupted files where the size fields were damaged; crafted inputs during security testing.","solutions":["Re-verify the archive with an independent tool (cabextract/7-Zip) to confirm the file is malformed","Regenerate the cabinet with makecab or 7-Zip if you control creation","If you wrote the CAB generator, ensure method-0 blocks always set cbData = cbUncomp","If the file is trusted and a standard tool accepts it, report a reader bug with the file"],"exampleFix":"// before (custom CAB writer)\nblock.cbData = payload.length;\nblock.cbUncomp = raw.length;\n// after\nif (method === 0) { block.cbData = raw.length; block.cbUncomp = raw.length; }","handlingStrategy":"try-catch","validationCode":"const t = Bun.$`cabextract -t ${path}`.quiet().nothrow();\nif ((await t).exitCode !== 0) throw new Error(`malformed cabinet: ${path}`);","typeGuard":null,"tryCatchPattern":"try {\n  await readCab(source, opts);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes('uncompressed CFDATA sizes do not match'))\n    throw new Error('Cabinet has an invalid stored (method 0) block — regenerate it with a standard tool.');\n  throw err;\n}","preventionTips":["Generate cabinets only with well-tested tools (makecab, 7-Zip, libmspack)","Never hand-patch CFDATA headers","Validate generated archives in CI with an extraction round-trip"],"tags":["archive","cab","malformed","stored-block"],"backgroundTag":"archive-structure-invalid","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}