Skip to content

Commit 1a26137

Browse files
committed
Reorder operation to eliminate possible overflow
1 parent 2cc58bb commit 1a26137

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/java/com/maxmind/db/MultiBuffer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public byte get() {
155155
/** {@inheritDoc} */
156156
@Override
157157
public Buffer get(byte[] dst) {
158-
if (position + dst.length > limit) {
158+
if (position > limit - dst.length) {
159159
throw new IndexOutOfBoundsException(
160160
"Read exceeds limit: position=" + position
161161
+ ", length=" + dst.length
@@ -359,4 +359,4 @@ public static MultiBuffer mapFromChannel(FileChannel channel) throws IOException
359359
}
360360
return new MultiBuffer(buffers, DEFAULT_CHUNK_SIZE);
361361
}
362-
}
362+
}

0 commit comments

Comments
 (0)