apache/cassandra · error · VIntOutOfRangeException
${value}
Error message
${value} What it means
VIntCoding.checkedCast(long) casts a long to int and verifies the value round-trips; if the long does not fit in 32 bits it throws VIntOutOfRangeException carrying the value. It mirrors Guava's Ints.checkedCast for varint-encoded quantities that must be int-sized.
Solutions
- Catch VIntOutOfRangeException and treat the message as corrupt (close/flag the connection).
- Range-check before casting: if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) handle explicitly.
- If 64 bits are genuinely needed, use the long value directly instead of checkedCast.
Example fix
// before
int len = VIntCoding.checkedCast(sizeLong);
// after
if (sizeLong < 0 || sizeLong > Integer.MAX_VALUE) throw new CorruptFrameException("size out of int range: " + sizeLong);
int len = (int) sizeLong; Defensive patterns
Strategy: try-catch
Validate before calling
boolean fitsInt = value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE;
Try / catch
try { int v = VIntCoding.checkedCast(value); } catch (VIntOutOfRangeException e) { throw new CorruptFrameException("varint out of int range: " + e.getMessage()); } Prevention
- Range-check untrusted varint-decoded lengths before casting to int.
- Keep values as long when the domain is 64-bit.
- Apply sanity limits (e.g. max frame size) on peer-supplied sizes.
When it happens
Trigger: Calling VIntCoding.checkedCast with a value > Integer.MAX_VALUE or < Integer.MIN_VALUE, e.g. an untrusted peer sends a huge varint length that is then checked-cast before allocation.
Common situations: Malicious or corrupted incoming protocol messages declaring sizes beyond int range; parsing 64-bit varints and assuming 32-bit values; version mismatches between sender and receiver.
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
- Reader index should be non-negative, but was
- Cannot serialize RedundantStatus larger than 0xFFFF…
- Corrupt HintsDescriptor serialization, problem:
- Expected instance of
- Invalid value for CQL type
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/a8ac71ca94818a27.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/utils/vint/VIntCoding.java:679
/** Compute the number of bytes that would be needed to encode a varint. */
public static int computeVIntSize(final long param)
{
return computeUnsignedVIntSize(encodeZigZag64(param));
}
/** Compute the number of bytes that would be needed to encode an unsigned varint. */
public static int computeUnsignedVIntSize(final long value)
{
int magnitude = Long.numberOfLeadingZeros(value | 1); // | with 1 to ensure magntiude <= 63, so (63 - 1) / 7 <= 8
// the formula below is hand-picked to match the original 9 - ((magnitude - 1) / 7)
return (639 - magnitude * 9) >> 6;
}
public static int checkedCast(long value)
{
int result = (int)value;
if ((long)result != value)
throw new VIntOutOfRangeException(value);
return result;
}
}
View on GitHub (pinned to 88fd0f6a0e)