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

Prevent crash due to large memory allocation #291

Merged
merged 1 commit into from
May 6, 2024

Conversation

serverwentdown
Copy link
Contributor

I was experiencing OOMKilled on my mc-router running in K8s, and found out through debug logs that I was receiving exceptionally large frame sizes:

time="2024-05-06T01:17:28Z" level=info msg="Got connection" client="10.42.0.1:52383"                                                                          time="2024-05-06T01:17:28Z" level=debug msg="Reading packet" client="10.42.0.1:52383"
time="2024-05-06T01:17:28Z" level=debug msg="Reading frame" client="10.42.0.1:52383"
time="2024-05-06T01:17:28Z" level=debug msg="Read frame length" client="10.42.0.1:52383" length=32426894721

Took a look at the code and this size of frame would certainly overallocate the buffer, causing OOM or DoS.

It should be noted the protocol does limit the number of bytes to 2^21-1: https://wiki.vg/Protocol#Packet_format

This PR limits the frame length to 2^21-1.

Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

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

Thanks! That's a potentially nasty issue that you fixed there.

@itzg itzg merged commit f34b6e8 into itzg:master May 6, 2024
2 checks passed
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.

2 participants