klauspost / reedsolomon

Reed-Solomon Erasure Coding in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic: runtime error: index out of range at Split()

huo-ju opened this issue · comments

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:

if len(data) < (r.totalShards * perShard) {

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!

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!