Tencent/matrix · error · InvalidParamException

InvalidParamException

Error message

InvalidParamException

What it means

Encoder.SetCoderProperties validates each CoderPropID/property pair. For NumFastBytes it first requires the value be an Int32 and then that it lie within [5, Base.kMatchMaxLen]; a non-int object or an out-of-range fast-bytes value throws InvalidParamException.

Solutions

  1. Set NumFastBytes to an Int32 within 5..Base.kMatchMaxLen (273), e.g. 32 or 64
  2. Cast/convert config values to int explicitly before building the properties array
  3. Clamp the configured value: Math.Max(5, Math.Min((int)v, 273))

Example fix

// before
props[1] = (long)numFastBytes; // boxed long -> InvalidParamException

// after
props[1] = (int)Math.Max(5, Math.Min(numFastBytes, 273));
Defensive patterns

Strategy: validation

Validate before calling

// C#
int ClampNumFastBytes(object v) {
    int n = Convert.ToInt32(v);
    if (n < 5 || n > 273) throw new ArgumentException("NumFastBytes must be in [5, 273]");
    return n;
}

Type guard

bool IsValidNumFastBytes(object v) => v is int i && i >= 5 && i <= 273;

Try / catch

// C#
try {
    encoder.SetCoderProperties(propIDs, props);
} catch (InvalidParamException ex) {
    throw new ArgumentException("Unsupported LZMA encoder property value", ex);
}

Prevention

When it happens

Trigger: Passing propIDs[NumFastBytes] with a value like 4, 0, 300, or a long/string/boxed non-Int32 instead of an int in the properties array.

Common situations: Tuning compression by setting NumFastBytes below 5 or above 273 (kMatchMaxLen), or storing the setting as long in config so boxing yields a long, not Int32.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

		static int FindMatchFinder(string s)
		{
			for (int m = 0; m < kMatchFinderIDs.Length; m++)
				if (s == kMatchFinderIDs[m])
					return m;
			return -1;
		}
	
		public void SetCoderProperties(CoderPropID[] propIDs, object[] properties)
		{
			for (UInt32 i = 0; i < properties.Length; i++)
			{
				object prop = properties[i];
				switch (propIDs[i])
				{
					case CoderPropID.NumFastBytes:
					{
						if (!(prop is Int32))
							throw new InvalidParamException();
						Int32 numFastBytes = (Int32)prop;
						if (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)
							throw new InvalidParamException();
						_numFastBytes = (UInt32)numFastBytes;
						break;
					}
					case CoderPropID.Algorithm:
					{
						/*
						if (!(prop is Int32))
							throw new InvalidParamException();
						Int32 maximize = (Int32)prop;
						_fastMode = (maximize == 0);
						_maxMode = (maximize >= 2);
						*/
						break;
					}
					case CoderPropID.MatchFinder:

View on GitHub (pinned to 3b8293bd65)