prestodb/presto · error · IllegalArgumentException
Length longer than value length
Error message
Length longer than value length
What it means
AbstractVariableWidthBlock.compareTo requires that the requested length does not exceed the actual length of the slice at the given position. If getSliceLength(position) < length, the comparison would read past the value, so the library throws IllegalArgumentException "Length longer than value length".
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/block/AbstractVariableWidthBlock.java:114
{
checkReadablePosition(position);
return getRawSlice(position).equals(getPositionOffset(position) + offset, length, otherSlice, otherOffset, length);
}
@Override
public long hash(int position, int offset, int length)
{
checkReadablePosition(position);
return XxHash64.hash(getRawSlice(position), getPositionOffset(position) + offset, length);
}
@Override
public int compareTo(int position, int offset, int length, Block otherBlock, int otherPosition, int otherOffset, int otherLength)
{
checkReadablePosition(position);
Slice rawSlice = getRawSlice(position);
if (getSliceLength(position) < length) {
throw new IllegalArgumentException("Length longer than value length");
}
return -otherBlock.bytesCompare(otherPosition, otherOffset, otherLength, rawSlice, getPositionOffset(position) + offset, length);
}
@Override
public int bytesCompare(int position, int offset, int length, Slice otherSlice, int otherOffset, int otherLength)
{
checkReadablePosition(position);
return getRawSlice(position).compareTo(getPositionOffset(position) + offset, length, otherSlice, otherOffset, otherLength);
}
@Override
public void writeBytesTo(int position, int offset, int length, BlockBuilder blockBuilder)
{
checkReadablePosition(position);
blockBuilder.writeBytes(getRawSlice(position), getPositionOffset(position) + offset, length);
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Clamp length: use Math.min(length, getSliceLength(position) - offset) before calling compareTo, or compute length via block.getSliceLength(position).
- Fix the caller to derive lengths from the same block/position being compared.
- Check for CHAR/FIXED-width assumptions in code operating on VARCHAR blocks.
- If slices come from deserialization, validate slice lengths during the read path to catch corruption earlier.
Example fix
// before int len = 10; // assumed fixed width leftBlock.compareTo(pos, 0, len, rightBlock, otherPos, 0, len); // after int len = Math.min(10, leftBlock.getSliceLength(pos) - 0); leftBlock.compareTo(pos, 0, len, rightBlock, otherPos, 0, len);
Defensive patterns
Strategy: validation
Validate before calling
static int safeCompareLength(Block varWidthBlock, int position, int requestedLength) {
int valueLength = varWidthBlock.getSliceLength(position);
checkArgument(requestedLength <= valueLength,
"requested length %s exceeds value length %s", requestedLength, valueLength);
return requestedLength;
} Try / catch
try {
int cmp = varBlock.compareTo(position, 0, length, other, otherPosition, 0, length);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Length longer than value length")) {
throw new DataCorruptionException("comparison length exceeds slice length", e);
}
throw e;
} Prevention
- Derive lengths from block.getSliceLength(position) rather than fixed-width assumptions.
- Do not mix CHAR-width computations with VARCHAR blocks.
- Validate slice lengths after deserializing pages from external sources.
When it happens
Trigger: Calling compareTo(position, offset, length, ...) with a length greater than the variable-width value's stored length — e.g. a fixed-length assumption applied to a VARCHAR block, or a length computed from a different block.
Common situations: Custom operator code comparing slices using lengths from another block or from fixed-width assumptions; corrupted deserialized slices whose reported lengths shrank; mismatches when comparing CHAR vs VARCHAR encodings.
Related errors
- otherOffset %d, length %d are invalid for otherSlice with le
- Offset is not monotonically ascending. offsets[%s]=%s, offse
- A null map must have zero entries
- Number of fields in RowBlock must be positive
- position is not valid
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/95fe02edbc16aa74.
Report an issue: GitHub.