Skip to content

Commit

Permalink
Fix data corruption in VectorCodec when using heap buffers
Browse files Browse the repository at this point in the history
patch by Ekaterina Dimitrova; reviewed by Alexandre Dutra and Bret McGuire for CASSANDRA-19333
  • Loading branch information
ekaterinadimitrova2 authored and absurdfarce committed Mar 22, 2024
1 parent 4c7133c commit 40a9a49
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@ Elements should at least precede themselves with their size (along the lines of
cqlType.getDimensions(), bytes.remaining()));
}

ByteBuffer slice = bytes.slice();
List<SubtypeT> rv = new ArrayList<SubtypeT>(cqlType.getDimensions());
for (int i = 0; i < cqlType.getDimensions(); ++i) {
ByteBuffer slice = bytes.slice();
slice.limit(elementSize);
// Set the limit for the current element
int originalPosition = slice.position();
slice.limit(originalPosition + elementSize);
rv.add(this.subtypeCodec.decode(slice, protocolVersion));
bytes.position(bytes.position() + elementSize);
// Move to the start of the next element
slice.position(originalPosition + elementSize);
// Reset the limit to the end of the buffer
slice.limit(slice.capacity());
}

/* Restore the input ByteBuffer to its original state */
bytes.rewind();

return CqlVector.newInstance(rv);
}

Expand Down

0 comments on commit 40a9a49

Please sign in to comment.