{"record":{"id":"da6246e686e75ea9","repo":"can1357/oh-my-pi","slug":"invalid-xz-delta-filter-properties","errorCode":null,"errorMessage":"Invalid XZ Delta filter properties","messagePattern":"Invalid XZ Delta filter properties","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/xz.ts","lineNumber":371,"sourceCode":"\t\t} else {\n\t\t\tconst register = instruction >>> 27;\n\t\t\tif (((instruction - 0x3117) << 18) >>> 0 >= (register & 0x1d)) {\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\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);","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/xz.ts#L353-L389","documentation":"This ArchiveError is thrown while applying the filters of an XZ block during decompression. Filter ID 3 is the Delta filter; per the XZ spec its properties must be exactly one byte (the distance minus 1). The library throws when the Delta filter's properties field has any other byte length, meaning the stream's filter properties are malformed.","triggerScenarios":"Decompressing an XZ stream whose block header declares a Delta filter (id 3) with a properties blob that is 0 bytes or more than 1 byte — i.e. the encoded properties size byte in the block header disagrees with the XZ spec.","commonSituations":"Corrupt or truncated archive files; hand-crafted or fuzzed XZ input; files produced by non-conformant compressors; byte-level corruption from a bad transfer or storage medium.","solutions":["Verify the source file is a valid XZ archive (test with `xz -t file.xz` or an equivalent tool) and re-obtain it if corrupt","Check for truncation: compare file size against the expected size or re-download/re-extract the archive","Confirm the producing tool is a spec-compliant XZ encoder; re-compress with standard xz if it was generated in-house","If the input is untrusted, treat this as expected rejection and surface a clear user-facing 'corrupt archive' message"],"exampleFix":"// before: properties encoded with wrong length\nconst filter = { id: 3, properties: new Uint8Array([4, 0]) };\n// after: Delta filter must carry exactly 1 property byte (distance - 1)\nconst filter = { id: 3, properties: new Uint8Array([3]) }; // distance = 4","handlingStrategy":"validation","validationCode":"// Inspect block filter properties before decode, or validate the archive externally first\nimport { $ } from 'bun';\nconst t = await $`xz -t archive.xz`.quiet().nothrow();\nif (t.exitCode !== 0) throw new Error('archive.xz is not a valid XZ stream');","typeGuard":"function isDeltaFilter(f: { id: number; properties: Uint8Array }): boolean {\n  return f.id !== 3 || f.properties.byteLength === 1;\n}","tryCatchPattern":"import { ArchiveError } from '@oh-my-pi/pi-utils/ar/codecs';\ntry {\n  await decodeXz(bytes);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.startsWith('Invalid XZ Delta filter')) {\n    throw new Error('Archive is corrupt: malformed Delta filter properties');\n  }\n  throw err;\n}","preventionTips":["Only decode XZ files produced by spec-compliant encoders (standard xz tool)","Verify archives with `xz -t` before programmatic decode in pipelines","Never hand-edit filter property bytes in compressed files","Validate file completeness (size/checksum from source) before decoding"],"tags":["xz","archive","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"}