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

THRIFT-5854: Move the checkReadBytesAvailable check before allocation #3100

Closed
wants to merge 1 commit into from

Conversation

bandle
Copy link
Contributor

@bandle bandle commented Feb 7, 2025

Affects: TCompactProtocol::readBinary

We allocated the string first and only checked afterward whether this allocation would be larger than MaxMessageSize allows. Since it throws, we throw away the buffer and the read, so we should check it earlier.

Furthermore, we check for varint_size + strlen instead of only strlen. However, since we can read varint using borrow and consume, this already decreases the remainingMessageSize by varint_size. Thus it can falsely trigger MaxMessageSize.

The tests for TCompactProtocol now use values closer to the egde case ana also test for successfull reads instead of only checking for exceptions.

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Affects: TCompactProtocol::readBinary

We allocated the string first and only checked afterward whether this allocation would be larger than MaxMessageSize allows. Since it throws, we throw away the buffer and the read, so we should check it earlier.

Furthermore, we check for varint_size + strlen instead of only strlen. However, since we can read varint using borrow and consume, this already decreases the remainingMessageSize by varint_size. Thus it can falsely trigger MaxMessageSize.

The tests for TCompactProtocol now use values closer to the egde case ana also test for successfull reads instead of only checking for exceptions.
@Jens-G Jens-G added the c++ label Feb 8, 2025
@Jens-G Jens-G closed this in 5c08893 Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants