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

Check for max allocation #374

Merged
merged 1 commit into from
Apr 20, 2024

Conversation

brianshih1
Copy link
Contributor

@brianshih1 brianshih1 commented Apr 20, 2024

Issue: #373

This PR checks to see if the size to allocate the array exceeds the max allocation size. This prevents getting panic: runtime: allocation size out of range when decoding arrays with an invalid size.

This is the code to reproduce the error before the fix:

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 281474976710656 (const maxAlloc untyped int = (1 << heapAddrBits) - (1-_64bit)*1)

@nrwiersma nrwiersma merged commit 0b21284 into hamba:main Apr 20, 2024
3 checks passed
@nrwiersma
Copy link
Member

Thanks for the contribution. Nice catch.

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

Successfully merging this pull request may close these issues.

2 participants