Detect incomplete reads from BAM schedule file in BAMSchedule before they become buffer underflows

This fix is similar, but distinct from the earlier fix to GATKBAMIndex. If we fail to read in
a complete 3-integer bin header from the BAM schedule file that the engine has written, throw a
ReviewedStingException (since this is our problem, not the user's) rather than allowing a
cryptic buffer underflow error to occur.

Note that this change does not fix the underlying problem in the engine, if there is one
(there may be an as-yet-undetected bug in the code that writes the bam schedule). It will
just make it easier for us to identify what's going wrong in the future.
This commit is contained in:
David Roazen 2012-03-09 12:13:53 -05:00
parent 32dee7ed9b
commit bc65f6326f
1 changed files with 8 additions and 1 deletions

View File

@ -407,7 +407,14 @@ public class BAMSchedule implements CloseableIterator<BAMScheduleEntry> {
position(currentPosition);
// Read data.
read(binHeader);
int binHeaderBytesRead = read(binHeader);
// Make sure we read in a complete bin header:
if ( binHeaderBytesRead < INT_SIZE_IN_BYTES * 3 ) {
throw new ReviewedStingException(String.format("Unable to read a complete bin header from BAM schedule file %s for BAM file %s. " +
"The BAM schedule file is likely incomplete/corrupt.",
scheduleFile.getAbsolutePath(), reader.getSamFilePath()));
}
// Decode contents.
binHeader.flip();