Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huo-ju opened this issue Jan 16, 2023 · 1 comment · Fixed by #234
Closed

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

huo-ju opened this issue Jan 16, 2023 · 1 comment · Fixed by #234

Comments

@huo-ju
Copy link

huo-ju commented Jan 16, 2023

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!

@klauspost
Copy link
Owner

klauspost commented Jan 17, 2023

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!

klauspost added a commit that referenced this issue Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants