{"record":{"id":"8a4a16e480199805","repo":"can1357/oh-my-pi","slug":"invalid-xz-stream-decoded-block-size-mismatch","errorCode":null,"errorMessage":"Invalid XZ stream: decoded block size mismatch","messagePattern":"Invalid XZ stream: decoded block size mismatch","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/xz.ts","lineNumber":475,"sourceCode":"\tif (declaredCompressed !== undefined && declaredCompressed !== compressedSize)\n\t\tthrow new ArchiveError(\"Invalid XZ stream: block compressed size mismatch\");\n\tif (declaredUncompressed !== undefined && declaredUncompressed !== record.uncompressedSize)\n\t\tthrow new ArchiveError(\"Invalid XZ stream: block uncompressed size mismatch\");\n\tconst compressedStart = offset + headerSize;\n\tconst compressedEnd = compressedStart + compressedSize;\n\tconst paddingSize = (4 - ((headerSize + compressedSize) & 3)) & 3;\n\tconst checkStart = compressedEnd + paddingSize;\n\tif (checkStart + integritySize > bytes.byteLength) throw new ArchiveError(\"Invalid XZ stream: truncated block data\");\n\tconst last = filters[filters.length - 1]!;\n\tif (last.id !== 0x21 || last.properties.byteLength !== 1)\n\t\tthrow new ArchiveError(`Unsupported XZ terminal filter ID 0x${last.id.toString(16)} (LZMA2 required)`);\n\tlet output = await lzma2Decompress(\n\t\tlast.properties[0]!,\n\t\tbytes.subarray(compressedStart, compressedEnd),\n\t\trecord.uncompressedSize,\n\t);\n\tif (output.byteLength !== record.uncompressedSize)\n\t\tthrow new ArchiveError(\"Invalid XZ stream: decoded block size mismatch\");\n\toutput = output.slice();\n\tfor (let index = filters.length - 2; index >= 0; index--) applyFilter(output, filters[index]!);\n\tfor (let index = compressedEnd; index < checkStart; index++)\n\t\tif (bytes[index] !== 0) throw new ArchiveError(\"Invalid XZ stream: non-zero block padding\");\n\tverifyCheck(checkId, output, bytes.subarray(checkStart, checkStart + integritySize));\n\tconst paddedEnd = offset + Math.ceil(record.unpaddedSize / 4) * 4;\n\tif (checkStart + integritySize !== paddedEnd)\n\t\tthrow new ArchiveError(\"Invalid XZ stream: block size does not match its index record\");\n\treturn output;\n}\n\n/** Whether bytes begin with the XZ stream-header magic. */\nexport function isXz(bytes: Uint8Array): boolean {\n\treturn bytes.byteLength >= XZ_MAGIC.byteLength && equalBytes(bytes.subarray(0, XZ_MAGIC.byteLength), XZ_MAGIC);\n}\n\n/** Decompress all concatenated streams in an XZ container within `maxOutput`. */\nexport async function xzDecompress(bytes: Uint8Array, maxOutput: number): Promise<Uint8Array> {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/xz.ts#L457-L493","documentation":"After LZMA2 decompression the output length must equal the uncompressed size recorded in the stream index. A mismatch means the compressed payload, LZMA2 properties, or index record are inconsistent — the decoder refuses to return wrong-sized data.","triggerScenarios":"xzDecompress decompresses a block whose lzma2Decompress output byteLength differs from record.uncompressedSize — e.g. the index claims a different size than the payload actually produces, or LZMA2 properties (dict size byte) are wrong for the payload.","commonSituations":"Bit-corrupted compressed data, archives whose index was rewritten or spliced, or files produced by encoders that misreport uncompressed sizes.","solutions":["Validate with `xz -t` and re-download the archive from a trusted source.","Re-compress with the standard xz tool if the producer was custom or non-standard.","Check that the compressed byte range was not altered (no manual slicing/splicing of the stream).","Report the archive as corrupt rather than attempting partial recovery."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const ok = await $`xz -t ${path}`.quiet().nothrow();\nif (ok.exitCode !== 0) throw new Error(`XZ integrity check failed: ${path}`);","typeGuard":null,"tryCatchPattern":"try {\n\treturn await xzDecompress(bytes, maxOutput);\n} catch (err) {\n\tif (err instanceof ArchiveError && /size mismatch/i.test(err.message)) {\n\t\tthrow new Error('Decompressed data does not match the index — archive is corrupt');\n\t}\n\tthrow err;\n}","preventionTips":["Verify checksums before decompression to catch bit rot early.","Never splice or rewrite XZ stream indexes.","Re-encode suspicious archives with the standard xz tool.","Monitor storage: recurring size mismatches indicate failing media."],"tags":["archive","xz","corrupt-data","size-mismatch"],"backgroundTag":"xz-stream-corrupt","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}