Skip to content

Commit

Permalink
Fix buffer overflow error in KryoBackedDecoder
Browse files Browse the repository at this point in the history
Fixes #19523
  • Loading branch information
jbartok authored and ljacomet committed Oct 13, 2022
1 parent 4a1c65e commit 3e38392
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -168,21 +168,30 @@ public void skipChunked() throws EOFException, IOException {
public <T> T decodeChunked(DecodeAction<Decoder, T> decodeAction) throws EOFException, Exception {
if (nested == null) {
nested = new KryoBackedDecoder(new InputStream() {
private int leftover = 0;

@Override
public int read() throws IOException {
throw new UnsupportedOperationException();
}

@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
if (leftover > 0) {
int count = Math.min(leftover, length);
leftover -= count;
readBytes(buffer, offset, count);
return count;
}

int count = readSmallInt();
if (count == 0) {
// End of stream has been reached
return -1;
}
if (count > length) {
// For now, assume same size buffers used to read and write
throw new UnsupportedOperationException();
leftover = count - length;
count = length;
}
readBytes(buffer, offset, count);
return count;
Expand Down

0 comments on commit 3e38392

Please sign in to comment.