Skip to content

Commit

Permalink
Fix some unsafe reads.
Browse files Browse the repository at this point in the history
If they failed to read the number of bytes, the return of `-1` would cause
infinite loops, with `-1` always less than the minimum `offset` of `0`.
  • Loading branch information
adam-vessey committed Jun 6, 2024
1 parent 21057cf commit 0948fd1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ private Directory read(TagSet tagSet) throws IOException {

private byte[] readBytes(int length) throws IOException {
byte[] data = new byte[length];
int n, offset = 0;
while ((n = inputStream.read(data, offset, data.length - offset)) < offset) {
offset += n;
}
inputStream.readFully(data);
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ private void readPlainTextExtension() throws IOException {

private byte[] read(int length) throws IOException {
byte[] data = new byte[length];
int n, offset = 0;
while ((n = inputStream.read(
data, offset, data.length - offset)) < offset) {
offset += n;
}
inputStream.readFully(data);
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,7 @@ private void readAPP14Segment() throws IOException {

private byte[] read(int length) throws IOException {
byte[] data = new byte[length];
int n, offset = 0;
while ((n = inputStream.read(
data, offset, data.length - offset)) < offset) {
offset += n;
}
inputStream.readFully(data);
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,7 @@ private void readCOCSegment() throws IOException {

private byte[] read(int length) throws IOException {
byte[] data = new byte[length];
int n, offset = 0;
while ((n = inputStream.read(
data, offset, data.length - offset)) < offset) {
offset += n;
}
inputStream.readFully(data);
return data;
}

Expand Down

0 comments on commit 0948fd1

Please sign in to comment.