panic: runtime error: index out of range at Split()
huo-ju opened this issue · comments
Ju Huo commented
Thank you for the great library!
I have a crash when use the Split() function, below is the details:
Version: main
Steps to reproduce
func main() {
data := make([]byte, 512)
var ecctest reedsolomon.Encoder
ecctest, _ = reedsolomon.New(1, 0)
_, _ = ecctest.Split(data)
}
Log
panic: runtime error: index out of range [512] with length 512
goroutine 1 [running]:
github.com/klauspost/reedsolomon.(*reedSolomon).Split(0x1?, {0xc0000a6000, 0x0?, 0x0?})
I have read the code, and find the issues may from this code:
Line 1564 in b413df3
When len(data) == (r.totalShards * perShard)
it will go to line 1577, and try to set data[512]
as 0
which will cause index out of range. It seems no need to do if len(data) == (r.totalShards * perShard)
?
Thanks!
Klaus Post commented
Yes, this is from the time when you couldn't specify 0 parity shards.
Simplified the code a bit to cover all cases.
Thanks for the report!