Skip to content

Commit

Permalink
[FLINK-34954][core] Kryo Input bug fix
Browse files Browse the repository at this point in the history
Handle edge case of zero length serialized bytes correctly.
  • Loading branch information
qinghui-xu authored and dannycranmer committed Apr 19, 2024
1 parent 131358b commit 3977982
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,14 @@ protected int require(int required) throws KryoException {
position = 0;
int bytesRead = 0;
int count;
while (true) {
while (bytesRead < required) {
count = fill(buffer, bytesRead, required - bytesRead);

if (count == -1) {
throw new KryoException(new EOFException("No more bytes left."));
}

bytesRead += count;
if (bytesRead == required) {
break;
}
}
limit = required;
return required;
Expand Down Expand Up @@ -121,18 +118,14 @@ public void readBytes(byte[] bytes, int offset, int count) throws KryoException
int bytesRead = 0;
int c;

while (true) {
while (bytesRead < count) {
c = inputStream.read(bytes, offset + bytesRead, count - bytesRead);

if (c == -1) {
throw new KryoException(new EOFException("No more bytes left."));
}

bytesRead += c;

if (bytesRead == count) {
break;
}
}
} catch (IOException ex) {
throw new KryoException(ex);
Expand Down

0 comments on commit 3977982

Please sign in to comment.