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

add message length check logic #66

Merged
merged 2 commits into from
Sep 12, 2023
Merged

Conversation

xxo1shine
Copy link
Collaborator

No description provided.


int length = Snappy.uncompressedLength(data);
if (length >= Parameter.MAX_MESSAGE_LENGTH) {
throw new IOException("message is too big, len=" + length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest optimizing the exception information, it should also be that the message after decompression is too large.

Copy link
Contributor

Choose a reason for hiding this comment

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

These two IOException can be merged into one.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can use P2pException MESSAGE_WITH_WRONG_LENGTH

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Modified, the two checks cannot be combined, the length must be checked before decompression.

}
return d2;
}
Copy link
Contributor

@317787106 317787106 Sep 12, 2023

Choose a reason for hiding this comment

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

int length = Snappy.uncompressedLength(data);
byte[] d2 = null;
if(length < Parameter.MAX_MESSAGE_LENGTH){
d2 = Snappy.uncompress(data);
}
if(length >= MAX_MESSAGE_LENGTH || d2.length >= Parameter.MAX_MESSAGE_LENGTH){
throws P2pException;
}

@xxo1shine xxo1shine merged commit 89aee2c into tronprotocol:develop Sep 12, 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 this pull request may close these issues.

3 participants