panic from slice out of bounds in bgzf.index
brentp opened this issue · comments
In func (r *ChunkReader) Read(p []byte) (int, error)
, I get:
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
github.com/biogo/hts/bgzf/index.(*ChunkReader).Read(0xc208994270, 0xc20883d20c, 0xdf4, 0xdf4, 0x7f80307beaa8, 0x0, 0x0)
/usr/local/src/gocode/src/github.com/biogo/hts/bgzf/index/index.go:64 +0x714
bufio.(*Reader).fill(0xc208e391a0)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(*Reader).ReadSlice(0xc208e391a0, 0xc20883d80a, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:295 +0x257
bufio.(*Reader).ReadBytes(0xc208e391a0, 0xc2085c780a, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:374 +0xd2
bufio.(*Reader).ReadString(0xc208e391a0, 0xa, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:414 +0x58
...
I printed out:
log.Println(r.chunks[0].End.Block, r.r.LastChunk().End.Block, len(p))
in the offending if statement and see:
2015/09/06 07:41:48 64366 3148 3572
I'm hoping you see an obvious solution (maybe using vOffset() is required in the if?), otherwise, I'll try to make a small test-case.
I'm confused, line 64 of index.go is blank: https://github.com/biogo/hts/blob/master/bgzf/index/index.go#L64
However, the fix is obvious, I should be using min(len(p), r.chunks[0].End.Block-r.r.LastChunk().End.Block). Can you send a test case?
I can't seem to conjure up a small test-case. I'm actually iterating over ExAC when I get this. Making the change you suggest does fix.
It would be line 62 + 1 line for import log and 1 line for the log.Println() that I added.