{"record":{"id":"174187ec20a94a8b","repo":"can1357/oh-my-pi","slug":"invalid-xz-bcj-filter-0x-filter-id-tostring-16","errorCode":null,"errorMessage":"Invalid XZ BCJ filter 0x${filter.id.toString(16)} properties","messagePattern":"Invalid XZ BCJ filter 0x(.+?) properties","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/xz.ts","lineNumber":376,"sourceCode":"\t\t\t}\n\t\t\tconst address = (read32BE(bytes, index + 4) - startOffset - index) >>> 0;\n\t\t\tinstruction2 = ((instruction >>> 12) | (address << 20)) >>> 0;\n\t\t\tinstruction = (0x17 | (register << 7) | ((address + 0x800) & 0xfffff000)) >>> 0;\n\t\t}\n\t\twrite32LE(bytes, index, instruction);\n\t\twrite32LE(bytes, index + 4, instruction2);\n\t\tindex += 6;\n\t}\n}\n\nfunction applyFilter(bytes: Uint8Array, filter: XzFilter): void {\n\tif (filter.id === 3) {\n\t\tif (filter.properties.byteLength !== 1) throw new ArchiveError(\"Invalid XZ Delta filter properties\");\n\t\tdeltaDecode(bytes, filter.properties[0]! + 1);\n\t\treturn;\n\t}\n\tif (filter.properties.byteLength !== 0 && filter.properties.byteLength !== 4)\n\t\tthrow new ArchiveError(`Invalid XZ BCJ filter 0x${filter.id.toString(16)} properties`);\n\tconst startOffset = filter.properties.byteLength === 4 ? read32LE(filter.properties, 0) : 0;\n\tconst alignment = filter.id === 6 ? 16 : filter.id === 8 || filter.id === 11 ? 2 : filter.id === 4 ? 1 : 4;\n\tif ((startOffset & (alignment - 1)) !== 0)\n\t\tthrow new ArchiveError(`Invalid XZ BCJ filter 0x${filter.id.toString(16)} start offset`);\n\tswitch (filter.id) {\n\t\tcase 4:\n\t\t\tx86Decode(bytes, startOffset);\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tpowerPcDecode(bytes, startOffset);\n\t\t\tbreak;\n\t\tcase 6:\n\t\t\tia64Decode(bytes, startOffset);\n\t\t\tbreak;\n\t\tcase 7:\n\t\t\tarmDecode(bytes, startOffset);\n\t\t\tbreak;\n\t\tcase 8:","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/xz.ts#L358-L394","documentation":"Thrown while applying XZ block filters: BCJ branch/call/jump filters (x86, PowerPC, IA-64, ARM, SPARC, ARM64, RISC-V) must have either empty properties or exactly 4 bytes holding the little-endian start offset. The library throws when a BCJ filter's properties have any other byte length, indicating a malformed block header.","triggerScenarios":"Decompressing an XZ stream whose block header declares a BCJ filter (id 4,5,6,8,9,10,11) with a properties blob of length 1, 2, 3, or >4 bytes.","commonSituations":"Corrupt or maliciously crafted archives; files produced by broken encoders; bit-flip corruption in the filter properties region of the block header.","solutions":["Validate the archive externally (`xz -t`) and replace the corrupt file with a known-good copy","Re-download or re-extract; check whether the transfer (FTP ascii mode, partial download) mangled the bytes","Re-compress the data with the standard xz tool if the file came from a custom pipeline","Wrap decode in error handling that reports 'corrupt archive' to the user rather than retrying the same bytes"],"exampleFix":"// before: truncated BCJ properties (2 bytes)\nconst filter = { id: 4, properties: new Uint8Array([0, 0]) };\n// after: BCJ properties are empty or a 4-byte LE start offset\nconst filter = { id: 4, properties: new Uint8Array(4) };","handlingStrategy":"validation","validationCode":"const t = await $`xz -t archive.xz`.quiet().nothrow();\nif (t.exitCode !== 0) throw new Error('archive.xz fails XZ integrity validation');","typeGuard":"function isBcjFilter(f: { id: number; properties: Uint8Array }): boolean {\n  return f.id === 3 || f.properties.byteLength === 0 || f.properties.byteLength === 4;\n}","tryCatchPattern":"try {\n  await decodeXz(bytes);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes('Invalid XZ BCJ filter')) {\n    throw new Error(`Archive uses malformed BCJ filter properties: ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Prefer default xz compression settings unless BCJ filters are specifically needed","Verify files with an independent XZ implementation before decoding","Detect truncation by comparing file size against a source-provided length","Treat untrusted archives as fail-closed: reject on any structural ArchiveError"],"tags":["xz","archive","bcj","corrupt-input","validation"],"backgroundTag":"corrupt-archive-input","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}