Love the tool! Been playing around for a while with it and I found that ReadBlock doesn't validate correctly the size of the block to read on a bam file, and that causes a heap overflow, which allows you to overwrite (among other things), the vtable of m_device. After failing to read the file, the program calls BgzfStream::Close(). This triggers the m_device->IsOpen() method, which allows us to exploit the overwritten vtable.
Hi there!
Love the tool! Been playing around for a while with it and I found that
ReadBlock
doesn't validate correctly the size of the block to read on a bam file, and that causes a heap overflow, which allows you to overwrite (among other things), the vtable ofm_device
. After failing to read the file, the program callsBgzfStream::Close()
. This triggers them_device->IsOpen()
method, which allows us to exploit the overwritten vtable.The problem, I think, is here: https://github.com/pezmaster31/bamtools/blob/9000c6b75f5fb3a9a9d4ab0d8984da953c18d1bb/src/api/internal/io/BgzfStream_p.cpp#L373
If the header provides a
blockLength
such thatblockLength < Constants::BGZF_BLOCK_HEADER_LENGTH
we underflow
remaining
, which then overflows the heap.To trigger the bug I used the command
bamtools index -in corrupted_file.bam