Skip to content

Commit

Permalink
add negative pos protection
Browse files Browse the repository at this point in the history
  • Loading branch information
lifepuzzlefun1 committed Jul 25, 2023
1 parent f3be23b commit a6f155a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public long forceWrite(boolean forceMetadata) throws IOException {

@Override
public synchronized int read(ByteBuf dest, long pos, int length) throws IOException {
// protect negative position read
if (pos < 0) {
throw new IllegalArgumentException("Negative position pos:" + pos);
}

long prevPos = pos;
while (length > 0) {
// check if it is in the write buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public synchronized int read(ByteBuf dest, long pos, int length) throws IOExcept
if (pos >= eof) {
return -1;
}

// protect negative position read
if (pos < 0) {
throw new IllegalArgumentException("Negative position pos:" + pos);
}

while (length > 0) {
// Check if the data is in the buffer, if so, copy it.
if (readBufferStartPosition <= currentPosition
Expand Down

0 comments on commit a6f155a

Please sign in to comment.