Tencent/matrix · error · InvalidParamException

InvalidParamException

Error message

InvalidParamException

What it means

Decoder.SetDecoderProperties validates the 5-byte LZMA properties header. The first check requires at least 5 bytes; a shorter array cannot encode lc/lp/pb plus the 4-byte dictionary size, so InvalidParamException is thrown.

Solutions

  1. Pass the real 5 property bytes read from the compressed stream (or the same values the encoder wrote)
  2. Validate properties != null && properties.Length >= 5 before calling SetDecoderProperties
  3. If the source lacks a header, generate properties yourself and write them to the output when compressing so both sides agree

Example fix

// before
decoder.SetDecoderProperties(headerBytes); // headerBytes may be short

// after
if (headerBytes == null || headerBytes.Length < 5)
    throw new IOException("Missing or truncated LZMA properties header");
decoder.SetDecoderProperties(headerBytes);
Defensive patterns

Strategy: validation

Validate before calling

// C#
bool HasValidLzmaHeader(byte[] p) => p != null && p.Length >= 5;
if (!HasValidLzmaHeader(props)) throw new IOException("LZMA props header must be 5 bytes");

Type guard

bool HasValidLzmaHeader(byte[] p) => p != null && p.Length >= 5;

Try / catch

// C#
try {
    decoder.SetDecoderProperties(props);
} catch (InvalidParamException) {
    throw new InvalidDataException("LZMA properties header missing or shorter than 5 bytes");
}

Prevention

When it happens

Trigger: Calling decoder.SetDecoderProperties(byte[]) with an array of length 0-4, e.g. reading a header from a truncated file or passing an empty/default array.

Common situations: Hard-coding new byte[4] by mistake, reading a 5-byte header from a stream that hit EOF, or forgetting the 5-byte props prefix that .lzma-alone files require.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/f7964e5119c08c6b. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/deps/liblzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs:352

						{
							if (rep0 == 0xFFFFFFFF)
								break;
							throw new DataErrorException();
						}
						m_OutWindow.CopyBlock(rep0, len);
						nowPos64 += len;
					}
				}
			}
			m_OutWindow.Flush();
			m_OutWindow.ReleaseStream();
			m_RangeDecoder.ReleaseStream();
		}

		public void SetDecoderProperties(byte[] properties)
		{
			if (properties.Length < 5)
				throw new InvalidParamException();
			int lc = properties[0] % 9;
			int remainder = properties[0] / 9;
			int lp = remainder % 5;
			int pb = remainder / 5;
			if (pb > Base.kNumPosStatesBitsMax)
				throw new InvalidParamException();
			UInt32 dictionarySize = 0;
			for (int i = 0; i < 4; i++)
				dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
			SetDictionarySize(dictionarySize);
			SetLiteralProperties(lp, lc);
			SetPosBitsProperties(pb);
		}

		public bool Train(System.IO.Stream stream)
		{
			_solid = true;
			return m_OutWindow.Train(stream);

View on GitHub (pinned to 3b8293bd65)