{"record":{"id":"439fd8f4a1f3b948","repo":"can1357/oh-my-pi","slug":"invalid-lzma2-stream-error-instanceof-error-e","errorCode":null,"errorMessage":"Invalid LZMA2 stream: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Invalid LZMA2 stream: (.+?)","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/lzma.ts","lineNumber":435,"sourceCode":"\t\t\t\tconst lp = property % 5;\n\t\t\t\tconst pb = Math.floor(property / 5);\n\t\t\t\tif (lc + lp > 4) throw new ArchiveError(\"Invalid LZMA2 literal properties\");\n\t\t\t\tdecoder.setProperties(lc, lp, pb);\n\t\t\t\tpropertiesSet = true;\n\t\t\t}\n\t\t\tif (packSize > bytes.byteLength - pos || unpackSize > maxOutput - decoder.outputPos)\n\t\t\t\tthrow new ArchiveError(\"Invalid LZMA2 chunk size\");\n\t\t\tif (resetsDictionary) decoder.resetDictionary();\n\t\t\telse if (resetsState) decoder.resetState();\n\t\t\tdecoder.decodeChunk(bytes.subarray(pos, pos + packSize), unpackSize);\n\t\t\tpos += packSize;\n\t\t\tneedDictionaryReset = false;\n\t\t}\n\t\tif (pos !== bytes.byteLength) throw new ArchiveError(\"Invalid LZMA2 stream: trailing data\");\n\t\treturn output.subarray(0, decoder.outputPos);\n\t} catch (error) {\n\t\tif (error instanceof ArchiveError) throw error;\n\t\tthrow new ArchiveError(`Invalid LZMA2 stream: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n}\n","sourceCodeStart":417,"sourceCodeEnd":438,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/lzma.ts#L417-L438","documentation":"This is the catch-all wrapper for the LZMA2 decode loop: any non-ArchiveError thrown inside the try block (e.g. a range error or internal LZMA decoder failure) is re-thrown as 'Invalid LZMA2 stream: <original message>'. It indicates the input violated LZMA2 framing or the decoder hit an unexpected internal state.","triggerScenarios":"Any internal error during lzmaDecompress's decode loop — malformed chunk control bytes, bad literal properties, dictionary/range-coder faults, or out-of-bounds subarray reads — surfaces with the inner error's message appended.","commonSituations":"Corrupted .xz/.lzma payloads; wrong dictionary/reset flags from a mangled control byte; decoding a file that isn't LZMA2 at all (wrong magic, wrong format); version mismatch between encoder features and decoder.","solutions":["Read the appended inner message to identify the concrete failure (e.g. bad properties vs range-coder error).","Verify the input is actually an LZMA2 stream (check container magic for .xz before extracting the payload).","Re-download or re-extract the archive and verify checksums.","Confirm no oversized/undersized maxOutput or partial buffer is being passed (see related chunk-size/trailing-data errors)."],"exampleFix":"// before: decoding a raw .xz file as LZMA2\nlzmaDecompress(xzFileBytes, max);\n// after: strip the .xz container first, then decode the LZMA2 payload\nlzmaDecompress(xzPayload, max);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return lzmaDecompress(bytes, maxOutput);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.startsWith(\"Invalid LZMA2 stream:\")) {\n    logger.error(\"LZMA2 decode failed\", { detail: err.message }); // inner cause is appended\n    throw new Error(\"Unreadable LZMA2 payload — verify format and integrity\", { cause: err });\n  }\n  throw err;\n}","preventionTips":["Parse the inner message: it names the concrete low-level failure.","Confirm the payload really is LZMA2 (check .xz magic before extraction).","Checksum-verify archives from network sources.","Route all decode failures through one ArchiveError-handling wrapper for consistent reporting."],"tags":["archive","lzma","malformed-input"],"backgroundTag":"corrupt-archive-bitstream","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}