Fix data corruption in VectorCodec when using heap buffers

patch by Ekaterina Dimitrova, reviewed by Andres de la Pena for CASSANDRA-19168
This commit is contained in:
Ekaterina Dimitrova 2024-01-08 10:09:49 -05:00
parent e3ce316cce
commit 1e8a1a21ab
3 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,5 @@
5.0-beta2
* Fix data corruption in VectorCodec when using heap buffers (CASSANDRA-19167)
* Avoid over-skipping of key iterators from static column indexes during mixed intersections (CASSANDRA-19278)
* Make concurrent_index_builders configurable at runtime (CASSANDRA-19266)
* Fix storage_compatibility_mode for streaming (CASSANDRA-19126)

View File

@ -127,18 +127,20 @@ public abstract class VectorCodec<E> extends TypeCodec<List<E>>
: String.format("Expected elements of uniform size, observed %d elements with total bytes %d",
type.getDimensions(), bytes.remaining());
ByteBuffer bb = bytes.slice();
ImmutableList.Builder<E> values = ImmutableList.builder();
for (int i = 0; i < type.getDimensions(); ++i)
{
ByteBuffer slice = bytes.slice();
slice.limit(elementSize);
values.add(subtypeCodec.deserialize(slice, protocolVersion));
bytes.position(bytes.position() + elementSize);
int originalPosition = bb.position();
// Set the limit for the current element
bb.limit(originalPosition + elementSize);
values.add(subtypeCodec.deserialize(bb, protocolVersion));
// Move to the start of the next element
bb.position(originalPosition + elementSize);
// Reset the limit to the end of the buffer
bb.limit(bb.capacity());
}
// Restore the input ByteBuffer to its original state
bytes.rewind();
return values.build();
}
}

View File

@ -404,7 +404,7 @@ public class CQLVectorTest extends CQLTester.InMemory
Vector<Integer> vector = vector(1, 2);
execute("INSERT INTO %s (pk, value) VALUES (0, ?)", vector);
// identitiy function
// identity function
String f = createFunction(KEYSPACE,
"",
"CREATE FUNCTION %s (x vector<int, 2>) " +