Skip to content

Commit

Permalink
Fix integer overflow in native scalar quantizer
Browse files Browse the repository at this point in the history
Offsets in memory segments should be computed as longs to avoid integer overflow on large segments.
  • Loading branch information
jimczi committed May 10, 2024
1 parent e10b3d4 commit eabd3b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public float score(int firstOrd, int secondOrd) throws IOException {
checkOrdinal(secondOrd);

final int length = dims;
int firstByteOffset = firstOrd * (length + Float.BYTES);
int secondByteOffset = secondOrd * (length + Float.BYTES);
long firstByteOffset = (long) firstOrd * (length + Float.BYTES);
long secondByteOffset = (long) secondOrd * (length + Float.BYTES);

MemorySegment firstSeg = segmentSlice(firstByteOffset, length);
input.seek(firstByteOffset + length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public float score(int firstOrd, int secondOrd) throws IOException {
checkOrdinal(secondOrd);

final int length = dims;
int firstByteOffset = firstOrd * (length + Float.BYTES);
int secondByteOffset = secondOrd * (length + Float.BYTES);
long firstByteOffset = (long) firstOrd * (length + Float.BYTES);
long secondByteOffset = (long) secondOrd * (length + Float.BYTES);

MemorySegment firstSeg = segmentSlice(firstByteOffset, length);
MemorySegment secondSeg = segmentSlice(secondByteOffset, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public float score(int firstOrd, int secondOrd) throws IOException {
checkOrdinal(secondOrd);

final int length = dims;
int firstByteOffset = firstOrd * (length + Float.BYTES);
int secondByteOffset = secondOrd * (length + Float.BYTES);
long firstByteOffset = (long) firstOrd * (length + Float.BYTES);
long secondByteOffset = (long) secondOrd * (length + Float.BYTES);

MemorySegment firstSeg = segmentSlice(firstByteOffset, length);
input.seek(firstByteOffset + length);
Expand Down

0 comments on commit eabd3b1

Please sign in to comment.