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

Decode Array - Panic: Allocation size out of range Error #373

Closed
brianshih1 opened this issue Apr 19, 2024 · 1 comment
Closed

Decode Array - Panic: Allocation size out of range Error #373

brianshih1 opened this issue Apr 19, 2024 · 1 comment

Comments

@brianshih1
Copy link
Contributor

Hello! I've been using Golang's fuzzer to test how ParseBytes deal with data that doesn't match the schema. I've reproduced an edge case where ParseBytes panics with panic: runtime: allocation size out of range. Here is the code:

package main

import "github.com/hamba/avro/v2"

func main() {
	rawSchema := []byte("{\"items\":{\"type\":\"boolean\"},\"type\":\"array\"}")

	schema, _ := avro.ParseBytes(rawSchema)

	data := []byte("\x02\x00\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\x00")
	var container any
	avro.Unmarshal(schema, data, &container)
}

This is the line of code that leads to the error. The size is 29787588086545014 while the maxAlloc size is const maxAlloc untyped int = (1 << heapAddrBits) - (1-_64bit)*1 // 281474976710656. Perhaps we should do a check here and return an error if it exceeds the maxAlloc size?

In my opinion ParseBytes should never panic and should instead return an error when dealing with invalid data.

@brianshih1 brianshih1 changed the title Panic: Allocation size out of range Error Decode Array - Panic: Allocation size out of range Error Apr 19, 2024
@brianshih1
Copy link
Contributor Author

PR to fix it: #374

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants