{"record":{"id":"c6b3a757b9579c2a","repo":"can1357/oh-my-pi","slug":"invalid-cab-archive-missing-lzx-aligned-tree","errorCode":null,"errorMessage":"Invalid CAB archive: missing LZX aligned tree","messagePattern":"Invalid CAB archive: missing LZX aligned tree","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/lzx.ts","lineNumber":307,"sourceCode":"\t\t\tlet matchOffset: number;\n\t\t\tif (slot === 0) {\n\t\t\t\tmatchOffset = this.#r0;\n\t\t\t} else if (slot === 1) {\n\t\t\t\tmatchOffset = this.#r1;\n\t\t\t\tthis.#r1 = this.#r0;\n\t\t\t\tthis.#r0 = matchOffset;\n\t\t\t} else if (slot === 2) {\n\t\t\t\tmatchOffset = this.#r2;\n\t\t\t\tthis.#r2 = this.#r0;\n\t\t\t\tthis.#r0 = matchOffset;\n\t\t\t} else {\n\t\t\t\tif (slot >= this.#positionBase.byteLength)\n\t\t\t\t\tthrow new ArchiveError(\"Invalid CAB archive: LZX position slot is out of range\");\n\t\t\t\tconst extra = this.#extraBits[slot]!;\n\t\t\t\tmatchOffset = this.#positionBase[slot]! - 2;\n\t\t\t\tif (this.#blockType === 2 && extra >= 3) {\n\t\t\t\t\tif (extra > 3) matchOffset += reader.readBits(extra - 3) * 8;\n\t\t\t\t\tif (!this.#alignedTable) throw new ArchiveError(\"Invalid CAB archive: missing LZX aligned tree\");\n\t\t\t\t\tmatchOffset += this.#alignedTable.decode(reader);\n\t\t\t\t} else if (extra !== 0) {\n\t\t\t\t\tmatchOffset += reader.readBits(extra);\n\t\t\t\t}\n\t\t\t\tthis.#r2 = this.#r1;\n\t\t\t\tthis.#r1 = this.#r0;\n\t\t\t\tthis.#r0 = matchOffset;\n\t\t\t}\n\n\t\t\tif (matchOffset <= 0 || matchOffset > Math.min(this.#decodedSize, this.#window.byteLength)) {\n\t\t\t\tthrow new ArchiveError(\"Invalid CAB archive: LZX match offset exceeds available history\");\n\t\t\t}\n\t\t\tfor (let index = 0; index < matchLength; index++) {\n\t\t\t\tconst source = (this.#windowPosition - matchOffset + this.#window.byteLength) % this.#window.byteLength;\n\t\t\t\tthis.#writeByte(this.#window[source]!, output, outputStart + produced + index);\n\t\t\t}\n\t\t\tproduced += matchLength;\n\t\t}","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/lzx.ts#L289-L325","documentation":"For aligned-offset blocks (type 2) with >= 3 extra bits, an aligned-offset Huffman tree must exist to decode the low 3 bits of the offset. It is null here, meaning block header setup did not build the aligned tree for this aligned block.","triggerScenarios":"decompressFrame -> #decodeRun processes an Aligned (type 2) match with extra >= 3 while #alignedTable is null.","commonSituations":"Internal state desync after a corrupt header, or a stream where the aligned tree read failed silently earlier.","solutions":["Use the full decompressFrame pipeline so block headers and trees are always built together.","Verify the CAB payload integrity.","Surface ArchiveError; decoding cannot continue without the tree."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = decompressFrame(frame);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes(\"missing LZX aligned tree\")) {\n    // header/tree desync — archive corrupt\n  } else throw err;\n}","preventionTips":["Always decode via the full frame pipeline so type-2 block headers build the aligned tree","Never skip or reorder block-header parsing","Validate archive integrity first"],"tags":["archive","cab","lzx","state-error"],"backgroundTag":"corrupt-archive-data","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}