This is an automated email from the ASF dual-hosted git repository.
absurdfarce pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/cassandra-java-driver.git
The following commit(s) were added to refs/heads/4.x by this push:
new 40a9a49d5 Fix data corruption in VectorCodec when using heap buffers
40a9a49d5 is described below
commit 40a9a49d50fac6abed2a5bb2cc2627e4085a399b
Author: Ekaterina Dimitrova <[email protected]>
AuthorDate: Mon Jan 29 14:07:59 2024 -0500
Fix data corruption in VectorCodec when using heap buffers
patch by Ekaterina Dimitrova; reviewed by Alexandre Dutra and Bret McGuire
for CASSANDRA-19333
---
.../oss/driver/internal/core/type/codec/VectorCodec.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git
a/core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java
b/core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java
index 1b663a29d..2c4d2200b 100644
---
a/core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java
+++
b/core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java
@@ -127,17 +127,19 @@ public class VectorCodec<SubtypeT extends Number>
implements TypeCodec<CqlVector
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);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]