{"record":{"id":"286c0778d243790f","repo":"can1357/oh-my-pi","slug":"invalid-xz-stream-non-zero-block-header-padding","errorCode":null,"errorMessage":"Invalid XZ stream: non-zero block header padding","messagePattern":"Invalid XZ stream: non-zero block header padding","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/xz.ts","lineNumber":452,"sourceCode":"\tif (crc32(bytes.subarray(offset, offset + headerSize - 4)) !== read32LE(bytes, offset + headerSize - 4))\n\t\tthrow new ArchiveError(\"Invalid XZ stream: block header CRC32 mismatch\");\n\tconst cursor: Cursor = { bytes, pos: offset + 1, limit: offset + headerSize - 4 };\n\tconst flags = bytes[cursor.pos++]!;\n\tif ((flags & 0x3c) !== 0) throw new ArchiveError(\"Unsupported XZ block flags\");\n\tconst filterCount = (flags & 3) + 1;\n\tconst declaredCompressed = (flags & 0x40) !== 0 ? readVarInt(cursor) : undefined;\n\tconst declaredUncompressed = (flags & 0x80) !== 0 ? readVarInt(cursor) : undefined;\n\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]!,","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/xz.ts#L434-L470","documentation":"After parsing the filters, every remaining byte of a block header up to its CRC32 must be zero padding per the XZ spec. A non-zero byte means the header is malformed, so the decoder rejects the stream. This is a strict conformance check on header padding.","triggerScenarios":"xzDecompress parses a block header whose filter list ends before the header size boundary and at least one padding byte is non-zero.","commonSituations":"Hand-crafted or tool-mangled XZ headers, corruption from a bad editor or transfer that overwrote header bytes, or output of a non-conforming custom encoder.","solutions":["Re-download/restore the file and validate with `xz -t` before decompressing.","Re-encode the archive with the standard xz tool if it was produced by custom code.","Verify you are not accidentally splicing or rewriting bytes of the archive in your pipeline.","Reject untrusted archives that fail validation instead of attempting repair."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { isXz } from '@oh-my-pi/pi-utils/ar/codecs/xz';\nif (!isXz(bytes)) throw new Error('Not an XZ stream');","typeGuard":null,"tryCatchPattern":"try {\n\treturn await xzDecompress(bytes, maxOutput);\n} catch (err) {\n\tif (err instanceof ArchiveError) throw new Error(`Corrupt XZ archive: ${err.message}`, { cause: err });\n\tthrow err;\n}","preventionTips":["Do not modify archive bytes between creation and decompression.","Re-encode with the stock xz tool if a custom encoder produced the file.","Checksum archives before use in automated pipelines.","Quarantine archives that fail validation instead of retrying."],"tags":["archive","xz","corrupt-data","format-validation"],"backgroundTag":"xz-stream-corrupt","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}