can1357/oh-my-pi · error · ArchiveError

Invalid LZMA2 stream: ${error instanceof Error ? error.messa

Error message

Invalid LZMA2 stream: ${error instanceof Error ? error.message : String(error)}

What it means

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.

Source

Thrown at packages/utils/src/ar/codecs/lzma.ts:435

				const lp = property % 5;
				const pb = Math.floor(property / 5);
				if (lc + lp > 4) throw new ArchiveError("Invalid LZMA2 literal properties");
				decoder.setProperties(lc, lp, pb);
				propertiesSet = true;
			}
			if (packSize > bytes.byteLength - pos || unpackSize > maxOutput - decoder.outputPos)
				throw new ArchiveError("Invalid LZMA2 chunk size");
			if (resetsDictionary) decoder.resetDictionary();
			else if (resetsState) decoder.resetState();
			decoder.decodeChunk(bytes.subarray(pos, pos + packSize), unpackSize);
			pos += packSize;
			needDictionaryReset = false;
		}
		if (pos !== bytes.byteLength) throw new ArchiveError("Invalid LZMA2 stream: trailing data");
		return output.subarray(0, decoder.outputPos);
	} catch (error) {
		if (error instanceof ArchiveError) throw error;
		throw new ArchiveError(`Invalid LZMA2 stream: ${error instanceof Error ? error.message : String(error)}`);
	}
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the appended inner message to identify the concrete failure (e.g. bad properties vs range-coder error).
  2. Verify the input is actually an LZMA2 stream (check container magic for .xz before extracting the payload).
  3. Re-download or re-extract the archive and verify checksums.
  4. Confirm no oversized/undersized maxOutput or partial buffer is being passed (see related chunk-size/trailing-data errors).

Example fix

// before: decoding a raw .xz file as LZMA2
lzmaDecompress(xzFileBytes, max);
// after: strip the .xz container first, then decode the LZMA2 payload
lzmaDecompress(xzPayload, max);
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return lzmaDecompress(bytes, maxOutput);
} catch (err) {
  if (err instanceof ArchiveError && err.message.startsWith("Invalid LZMA2 stream:")) {
    logger.error("LZMA2 decode failed", { detail: err.message }); // inner cause is appended
    throw new Error("Unreadable LZMA2 payload — verify format and integrity", { cause: err });
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/439fd8f4a1f3b948. Report an issue: GitHub.