{"record":{"id":"ccfdbe32ecc35aba","repo":"can1357/oh-my-pi","slug":"invalid-xz-stream-block-uncompressed-size-mismatc","errorCode":null,"errorMessage":"Invalid XZ stream: block uncompressed size mismatch","messagePattern":"Invalid XZ stream: block uncompressed size mismatch","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/xz.ts","lineNumber":460,"sourceCode":"\tconst filters: XzFilter[] = [];\n\tfor (let index = 0; index < filterCount; index++) {\n\t\tconst id = readVarInt(cursor);\n\t\tconst propertySize = readVarInt(cursor);\n\t\tif (propertySize > cursor.limit - cursor.pos)\n\t\t\tthrow new ArchiveError(\"Invalid XZ stream: truncated filter properties\");\n\t\tfilters.push({ id, properties: bytes.slice(cursor.pos, cursor.pos + propertySize) });\n\t\tcursor.pos += propertySize;\n\t}\n\twhile (cursor.pos < cursor.limit)\n\t\tif (bytes[cursor.pos++] !== 0) throw new ArchiveError(\"Invalid XZ stream: non-zero block header padding\");\n\tconst integritySize = checkSize(checkId);\n\tconst compressedSize = record.unpaddedSize - headerSize - integritySize;\n\tif (!Number.isSafeInteger(compressedSize) || compressedSize <= 0)\n\t\tthrow new ArchiveError(\"Invalid XZ stream: compressed block size is invalid\");\n\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++)","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/xz.ts#L442-L478","documentation":"The block header optionally declares the uncompressed size (flags bit 0x80). When present, it must equal the uncompressed size recorded in the stream index. A mismatch means the header and index contradict each other and the stream is invalid.","triggerScenarios":"xzDecompress reads a block header with the uncompressed-size-present flag set whose declared value differs from record.uncompressedSize.","commonSituations":"Corrupted downloads, third-party or buggy XZ encoders writing inconsistent metadata, or archives modified after creation.","solutions":["Validate the file with `xz -t` and re-download or re-compress if it fails.","Re-encode with the standard xz tool if a custom producer wrote mismatched sizes.","Confirm your pipeline does not alter archive bytes between creation and decompression.","Handle ArchiveError explicitly so invalid archives fail fast with a clear message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const ok = await $`xz -t ${path}`.quiet().nothrow();\nif (ok.exitCode !== 0) throw new Error(`XZ archive failed integrity test: ${path}`);","typeGuard":null,"tryCatchPattern":"try {\n\treturn await xzDecompress(bytes, maxOutput);\n} catch (err) {\n\tif (err instanceof ArchiveError && /uncompressed size mismatch/i.test(err.message)) {\n\t\tthrow new Error('Header/index disagree on uncompressed size — archive is corrupt');\n\t}\n\tthrow err;\n}","preventionTips":["Validate archives immediately after download or build.","Re-encode with stock xz if a custom producer wrote the stream.","Reject archives with post-creation modifications.","Log ArchiveError messages verbatim to aid diagnosing corrupt producers."],"tags":["archive","xz","corrupt-data","index-mismatch"],"backgroundTag":"xz-stream-corrupt","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}