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

BUGFIX: don't allocate more memory than what can be read from io.Reader #42

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

inteon
Copy link
Contributor

@inteon inteon commented Apr 10, 2024

Memory was allocated based on encoded length instead of the length of the io.Reader.
This makes it possible for an attacker to cause DOS due to unexpected high memory usage (max MaxPacketLengthBytes) with a reader is actually limited in length.

// make([]byte, length) can allocate up to MaxPacketLengthBytes which is
// currently 2 GB. This can cause memory related crashes when fuzzing in
// parallel or on memory constrained devices.
MaxPacketLengthBytes = 65536
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the issue described above.

…ength of the io.Reader, causing potential DOS due to unexpected high memory usage (max MaxPacketLengthBytes)

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon
Copy link
Contributor Author

inteon commented Apr 12, 2024

I replaced io.ReadAll with ioutil.ReadAll, so the code works on go <= 1.15 too.

@inteon
Copy link
Contributor Author

inteon commented Apr 22, 2024

@johnweldon PTAL

Copy link
Contributor

@johnweldon johnweldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you

@johnweldon johnweldon merged commit 5679dfd into go-asn1-ber:master Apr 22, 2024
9 checks passed
@inteon
Copy link
Contributor Author

inteon commented Apr 22, 2024

@johnweldon Thanks for merging the PR, can this be a 1.5.6 release?

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 this pull request may close these issues.

None yet

2 participants