Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private void validateOffsetBuffer(ValueVector vector, int valueCount) {

// verify that the values in the offset buffer is non-decreasing
int prevValue = offsetBuffer.getInt(0);
validateOrThrow(
prevValue >= 0, "The value at position 0 of the offset buffer is negative: %s.", prevValue);
for (int i = 1; i <= valueCount; i++) {
int curValue = offsetBuffer.getInt(i * 4);
validateOrThrow(
Expand All @@ -77,6 +79,10 @@ private void validateLargeOffsetBuffer(ValueVector vector, int valueCount) {

// verify that the values in the large offset buffer is non-decreasing
long prevValue = offsetBuffer.getLong(0);
validateOrThrow(
prevValue >= 0L,
"The value at position 0 of the large offset buffer is negative: %s.",
prevValue);
for (int i = 1; i <= valueCount; i++) {
long curValue = offsetBuffer.getLong((long) i * 8);
validateOrThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.Float4Vector;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.LargeVarBinaryVector;
import org.apache.arrow.vector.LargeVarCharVector;
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.ViewVarCharVector;
import org.apache.arrow.vector.complex.DenseUnionVector;
Expand Down Expand Up @@ -463,4 +465,50 @@ public void testValidateDecimal256() {
assertTrue(e.getMessage().contains("Decimal"));
}
}

@Test
public void testValidateNegativeFirstOffset() {
byte[] aaa = "aaa".getBytes(StandardCharsets.UTF_8);
byte[] bbb = "bbb".getBytes(StandardCharsets.UTF_8);

try (final VarBinaryVector vector = new VarBinaryVector("v", allocator)) {
setVector(vector, aaa, bbb);
vector.getOffsetBuffer().setInt(0, -4);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector));
assertTrue(
e.getMessage().contains("The value at position 0 of the offset buffer is negative"));
}

try (final LargeVarBinaryVector vector = new LargeVarBinaryVector("v", allocator)) {
vector.setSafe(0, aaa);
vector.setSafe(1, bbb);
vector.setValueCount(2);
vector.getOffsetBuffer().setLong(0, -4);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector));
assertTrue(
e.getMessage()
.contains("The value at position 0 of the large offset buffer is negative"));
}

try (final ListVector vector = ListVector.empty("v", allocator)) {
setVector(vector, Arrays.asList(1, 2, 3), Arrays.asList(4, 5));
vector.getOffsetBuffer().setInt(0, -1);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector));
assertTrue(
e.getMessage().contains("The value at position 0 of the offset buffer is negative"));
}

try (final LargeListVector vector = LargeListVector.empty("v", allocator)) {
setVector(vector, Arrays.asList(1, 2, 3), Arrays.asList(4, 5));
vector.getOffsetBuffer().setLong(0, -1);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector));
assertTrue(
e.getMessage()
.contains("The value at position 0 of the large offset buffer is negative"));
}
}
}
Loading