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
4 changes: 4 additions & 0 deletions vector/src/main/java/org/apache/arrow/vector/util/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ private static Optional<Integer> validateUTF8Internal(byte[] utf8, int start, in
} // switch (state)
count++;
}
if (state != LEAD_BYTE) {
// the input ended in the middle of a multi-byte sequence
return Optional.of(count);
}
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,28 @@ public void testValidateLargeVarCharUTF8() {
}
}

@Test
public void testValidateTruncatedUTF8() {
// multi-byte sequences cut short at the end of the value
byte[][] truncated = {
{(byte) 0xC3}, {(byte) 0xE2, (byte) 0x82}, {'a', (byte) 0xF0, (byte) 0x9F, (byte) 0x98}
};
for (byte[] value : truncated) {
try (final VarCharVector vector = new VarCharVector("v", allocator)) {
setVector(vector, "aaa".getBytes(StandardCharsets.UTF_8), value);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, vector::validateFull);
assertTrue(e.getMessage().contains("UTF"));
}
try (final LargeVarCharVector vector = new LargeVarCharVector("v", allocator)) {
setVector(vector, "aaa".getBytes(StandardCharsets.UTF_8), value);
ValidateUtil.ValidateException e =
assertThrows(ValidateUtil.ValidateException.class, vector::validateFull);
assertTrue(e.getMessage().contains("UTF"));
}
}
}

@Test
public void testValidateDecimal() {
try (final DecimalVector vector =
Expand Down
Loading