Skip to content

Commit

Permalink
Handling corrupt file exception in QueueFile readElement. (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyachandra14 authored Jul 20, 2021
1 parent aa43afa commit 8cb94f9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions batching/src/main/java/com/flipkart/batching/tape/QueueFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,22 @@ private void readHeader() throws IOException {
raf.seek(0);
raf.readFully(buffer);
fileLength = readInt(buffer, 0);
elementCount = readInt(buffer, 4);
int firstOffset = readInt(buffer, 8);
int lastOffset = readInt(buffer, 12);
if (fileLength > raf.length()) {
throw new IOException(
"File is truncated. Expected length: " + fileLength + ", Actual length: " + raf.length());
} else if (fileLength <= 0) {
throw new IOException(
"File is corrupt; length stored in header (" + fileLength + ") is invalid.");
} else if (firstOffset < 0 || fileLength <= wrapPosition(firstOffset)) {
throw new IOException(
"File is corrupt; first position stored in header (" + firstOffset + ") is invalid.");
} else if (lastOffset < 0 || fileLength <= wrapPosition(lastOffset)) {
throw new IOException(
"File is corrupt; last position stored in header (" + lastOffset + ") is invalid.");
}
elementCount = readInt(buffer, 4);
int firstOffset = readInt(buffer, 8);
int lastOffset = readInt(buffer, 12);
first = readElement(firstOffset);
last = readElement(lastOffset);
}
Expand Down

0 comments on commit 8cb94f9

Please sign in to comment.