Skip to content

Commit f24db70

Browse files
committed
fix issue reading off the end of the ByteBuffer if ptr > 0
1 parent 55552ca commit f24db70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

java/src/json/ext/SWARBasicStringEncoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ void encode(ByteList src) throws IOException {
2424
int pos = 0;
2525

2626
ByteBuffer bb = ByteBuffer.wrap(ptrBytes, 0, len);
27-
while (pos + 8 <= len) {
27+
while (ptr + pos + 8 <= len) {
2828
long x = bb.getLong(ptr + pos);
2929
if (skipChunk(x)) {
3030
pos += 8;
3131
continue;
3232
}
33-
int chunkEnd = pos + 8;
34-
while (pos < chunkEnd) {
33+
int chunkEnd = ptr + pos + 8;
34+
while (ptr + pos < chunkEnd) {
3535
int ch = Byte.toUnsignedInt(ptrBytes[ptr + pos]);
3636
int ch_len = ESCAPE_TABLE[ch];
3737
if (ch_len > 0) {
@@ -43,7 +43,7 @@ void encode(ByteList src) throws IOException {
4343
}
4444
}
4545

46-
if (pos + 4 <= len) {
46+
if (ptr + pos + 4 <= len) {
4747
int x = bb.getInt(ptr + pos);
4848
if (skipChunk(x)) {
4949
pos += 4;

0 commit comments

Comments
 (0)