Skip to content
Closed
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 @@ -461,6 +461,15 @@ byte[] toKey(Object value, byte prefix) {

if (value instanceof String) {
byte[] str = ((String) value).getBytes(UTF_8);
for (byte b : str) {
if (b == KEY_SEPARATOR) {
// String bytes are copied verbatim into the key, so an embedded key
// separator would corrupt the index key structure and mix entries across
// range scans and deletes. Reject such values outright.
throw new IllegalArgumentException(
"Index string values cannot contain the key separator (0x00) byte.");
}
}
result = new byte[str.length + 1];
result[0] = prefix;
System.arraycopy(str, 0, result, 1, str.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@ byte[] toKey(Object value, byte prefix) {

if (value instanceof String) {
byte[] str = ((String) value).getBytes(UTF_8);
for (byte b : str) {
if (b == KEY_SEPARATOR) {
// String bytes are copied verbatim into the key, so an embedded key
// separator would corrupt the index key structure and mix entries across
// range scans and deletes. Reject such values outright.
throw new IllegalArgumentException(
"Index string values cannot contain the key separator (0x00) byte.");
}
}
result = new byte[str.length + 1];
result[0] = prefix;
System.arraycopy(str, 0, result, 1, str.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,12 @@ public String id(boolean illegalParam) {

}


@Test
public void testStringValuesRejectKeySeparator() throws Exception {
LevelDBTypeInfo.Index idx = newTypeInfo(CustomType1.class).indices().iterator().next();
assertThrows(IllegalArgumentException.class, () -> idx.toKey("key\u0000suffix"));
assertThrows(IllegalArgumentException.class,
() -> idx.toKey(new String[] { "ok", "bad\u0000" }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,12 @@ public String id(boolean illegalParam) {

}


@Test
public void testStringValuesRejectKeySeparator() throws Exception {
RocksDBTypeInfo.Index idx = newTypeInfo(CustomType1.class).indices().iterator().next();
assertThrows(IllegalArgumentException.class, () -> idx.toKey("key\u0000suffix"));
assertThrows(IllegalArgumentException.class,
() -> idx.toKey(new String[] { "ok", "bad\u0000" }));
}
}