You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Java] DictionaryEncoder doesn't crash when decoding index outside of Dictionary #1158
Describe the bug, including details regarding any error messages, version, and platform.
Background
When manually creating an encoded vector, with values referencing indices in a Dictionary, it is possible to have values equal to valueCount of the Dictionary vector i.e. one index out of bounds. This is interpreted as a null value in the Dictionary.
Example
Dictionary
Index
Original Value
0
Foo
Encoded Vector - 1
Index
Encoded Value
Expected Decode Outcome
Actual Outcome
0
0
Return the original value
Returns the original value
Encoded Vector - 2
Index
Encoded Value
Expected Decode Outcome
Actual Outcome
0
1
Raise IllegalArgumentException
Returns null
Encoded Vector - 3
Index
Encoded Value
Expected Decode Outcome
Actual Outcome
0
2
Raise IllegalArgumentException
Raises IllegalArgumentException
Test to reproduce the error
@TestpublicvoidtestReferencingIndexOutOfBounds() {
// Index at which the original value will be stored at in the dictionaryvarencodedIndex = 0;
// The encoded value that references an index in the dictionaryvarindexReferenced = 1;
try (finalIntVectorencodedVector = newIntVector("encodings", allocator);
finalVarCharVectordictionaryVector = newVarCharVector("dict", allocator); ) {
varoriginalValue = "Foo";
dictionaryVector.allocateNew(1);
dictionaryVector.setValueCount(1);
dictionaryVector.set(encodedIndex, originalValue.getBytes(StandardCharsets.UTF_8));
encodedVector.allocateNew(1);
encodedVector.setValueCount(1);
encodedVector.set(0, indexReferenced);
Dictionarydictionary =
newDictionary(dictionaryVector, newDictionaryEncoding(1L, false, null));
try (ValueVectordecoded = DictionaryEncoder.decode(encodedVector, dictionary)) {
fail("There should be an exception when decoding index outside dictionary's range.");
} catch (Exceptione) {
assertEquals("Provided dictionary does not contain value for index " + indexReferenced, e.getMessage());
}
}
}
Activity
apacheGH-1158: Fix inclusive bounds checking for DictionaryDecoder
apacheGH-1158: Fix inclusive bounds checking for DictionaryDecoder
apacheGH-1158: Fix inclusive bounds checking for DictionaryDecoder