Skip to content

Commit

Permalink
AVRO-4048: Ignore negative return values for InputStream skip
Browse files Browse the repository at this point in the history
  • Loading branch information
belugabehr committed Sep 1, 2024
1 parent c7b79bf commit b130ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
37 changes: 10 additions & 27 deletions lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -797,20 +797,12 @@ protected void skipSourceBytes(long length) throws IOException {
continue;
}
// The inputStream contract is evil.
// zero "might" mean EOF. So check for 2 in a row, we will
// infinite loop waiting for -1 with some classes others
// spuriously will return 0 on occasion without EOF
if (n == 0) {
if (readZero) {
isEof = true;
throw new EOFException();
}
readZero = true;
continue;
// zero "might" mean EOF. So check for 2 in a row.
if (readZero) {
isEof = true;
throw new EOFException();
}
// read negative
isEof = true;
throw new EOFException();
readZero = true;
}
}

Expand All @@ -826,21 +818,12 @@ protected long trySkipBytes(long length) throws IOException {
continue;
}
// The inputStream contract is evil.
// zero "might" mean EOF. So check for 2 in a row, we will
// infinite loop waiting for -1 with some classes others
// spuriously will return 0 on occasion without EOF
if (n == 0) {
if (readZero) {
isEof = true;
break;
}
readZero = true;
continue;
// zero "might" mean EOF. So check for 2 in a row
if (readZero) {
isEof = true;
break;
}
// read negative
isEof = true;
break;

readZero = true;
}
} catch (EOFException eof) {
isEof = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public ByteBuffer readBytes(ByteBuffer old) throws IOException {
protected void doSkipBytes(long length) throws IOException {
while (length > 0) {
long n = in.skip(length);
if (n <= 0) {
if (n == 0) {
throw new EOFException();
}
length -= n;
Expand Down

0 comments on commit b130ffa

Please sign in to comment.