{"record":{"id":"3eb7b0da2a57ec7d","repo":"can1357/oh-my-pi","slug":"invalid-lzma2-chunk-size","errorCode":null,"errorMessage":"Invalid LZMA2 chunk size","messagePattern":"Invalid LZMA2 chunk size","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/codecs/lzma.ts","lineNumber":424,"sourceCode":"\t\t\tconst resetsState = control >= 0xa0;\n\t\t\tconst setsProperties = control >= 0xc0;\n\t\t\tif (needDictionaryReset && !resetsDictionary)\n\t\t\t\tthrow new ArchiveError(\"Invalid LZMA2 stream: dictionary was not initialized\");\n\t\t\tif (!propertiesSet && !setsProperties)\n\t\t\t\tthrow new ArchiveError(\"Invalid LZMA2 stream: properties were not initialized\");\n\t\t\tif (setsProperties) {\n\t\t\t\tlet property = takeByte();\n\t\t\t\tif (property >= 9 * 5 * 5) throw new ArchiveError(\"Invalid LZMA2 properties\");\n\t\t\t\tconst lc = property % 9;\n\t\t\t\tproperty = Math.floor(property / 9);\n\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":406,"sourceCodeEnd":438,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/codecs/lzma.ts#L406-L438","documentation":"LZMA2 chunk headers declare packed and unpacked sizes. This error is thrown when the chunk header's packSize exceeds the remaining input bytes, or its unpackSize exceeds the remaining decoder output capacity (maxOutput minus already-written output). It guards against buffers that lie about their own chunk framing.","triggerScenarios":"Calling lzmaDecompress (decodeLzma2) with a truncated input buffer whose last chunk header promises more packed bytes than remain, or an unpackSize larger than the remaining maxOutput budget.","commonSituations":"Truncated .xz/.lzma downloads; passing a subarray that cuts off mid-chunk; calling with a maxOutput smaller than the actual decompressed size; corrupted archive payload.","solutions":["Increase the maxOutput parameter to at least the expected decompressed size.","Pass the complete LZMA2 stream bytes — verify the input wasn't truncated (compare against source size/checksum).","Validate the container (.xz) integrity before extracting the LZMA2 payload.","Ensure you're not resuming mid-stream without preserving decoder state; start from the stream beginning."],"exampleFix":"// before\nlzmaDecompress(bytes, 1024);\n// after: size the output to the file's recorded uncompressed size\nlzmaDecompress(bytes, recordedUncompressedSize);","handlingStrategy":"validation","validationCode":"if (!Number.isSafeInteger(maxOutput) || maxOutput <= 0) throw new Error(\"maxOutput must be a positive integer\");\nif (bytes.byteLength === 0) throw new Error(\"Empty LZMA2 payload\");","typeGuard":null,"tryCatchPattern":"try {\n  return lzmaDecompress(bytes, maxOutput);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes(\"chunk size\")) {\n    throw new Error(\"LZMA2 payload truncated or maxOutput too small — check stream completeness and output budget\", { cause: err });\n  }\n  throw err;\n}","preventionTips":["Size maxOutput from the container's recorded uncompressed size, not a guess.","Read the entire stream — never decode from a partial buffer.","Validate container (.xz) integrity before extracting the LZMA2 payload.","Start decoding at the stream beginning; don't resume mid-chunk."],"tags":["archive","lzma","truncated-input"],"backgroundTag":"truncated-compressed-stream","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}