-
Notifications
You must be signed in to change notification settings - Fork 167
aws_base64_compute_encoded_len() is now exact, doesn't add 1 extra for null-terminator #1188
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
Merged
DmitriyMusatkin
merged 6 commits into
main
from
knock-it-off-with-this-null-terminator-nonsense
Feb 21, 2025
Merged
aws_base64_compute_encoded_len() is now exact, doesn't add 1 extra for null-terminator #1188
DmitriyMusatkin
merged 6 commits into
main
from
knock-it-off-with-this-null-terminator-nonsense
Feb 21, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ating sometimes. Also much simpler. - aws_base64_compute_decoded_len() math can't overflow anymore
…t answer too, instead of sometimes overestimating
…of it back, but document the math tricks that confused me
TingDaoK
approved these changes
Feb 14, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1188 +/- ##
=======================================
Coverage 84.21% 84.21%
=======================================
Files 57 57
Lines 5979 5973 -6
=======================================
- Hits 5035 5030 -5
+ Misses 944 943 -1 ☔ View full report in Codecov by Sentry. |
This was referenced Feb 15, 2025
DmitriyMusatkin
approved these changes
Feb 21, 2025
graebm
added a commit
to awslabs/aws-crt-cpp
that referenced
this pull request
Mar 17, 2025
…r null terminator. See: awslabs/aws-c-common#1188
graebm
added a commit
to awslabs/aws-crt-cpp
that referenced
this pull request
Mar 17, 2025
**Issue:** aws-sdk-cpp needs to send streaming requests of unknown content length. This isn't currently supported in our HTTP/1 client. **Description of changes:** - Update submodules: aws-c-auth v0.8.5 -> v0.8.6 aws-c-cal v0.8.3 -> v0.8.7 aws-c-common v0.11.1 -> v0.12.0 aws-c-event-stream v0.5.2 -> v0.5.4 aws-c-http v0.9.3 -> v0.9.5 aws-c-io v0.16.0 -> v0.17.0 aws-c-s3 v0.7.11 -> v0.7.13 aws-lc v1.46.1 -> v1.48.4 s2n v1.5.13 -> v1.5.14 - Bring in change that allows HTTP/1 streams of unknown length: - awslabs/aws-c-http#506 - Remove hack in Base64 decoded logic, which is no longer necessary due to this change: - awslabs/aws-c-common#1188
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
One of the core principles of aws_byte_buf and aws_byte_cursor, is you DO NOT assume there's a null-terminator, because null-terminators, and the resulting confusion between string "length" and "size" have led to so many bugs in the long history of C.
But
aws_base64_encode()
tried to be "nice" and add a secret null-terminator after.len
, but before.capacity
. To achieve this,aws_base64_compute_encoded_len()
would say it needed 1 more byte than necessary. This caused trouble, catching Dmitriy off guard the other day. Searching for uses, I see aws-crt-cpp also once had a bug due to this (fixed in this PR)In changing this, I found that
aws_hex_encode()
did similar, but even worse. It always added a null-terminator, and included the null-terminator in the.len
! Bad! Fortunately, this function was never used except in generating random data for tests. When Bret needed a function like this in 2019 for signing, he avoided this function entirely and built his own alternate version that doesn't add a null-terminator (it has other differences too).Description of changes:
aws_hex_encode()
doesn't add null-terminator anymoreaws_hex_compute_encoded_len()
updated to account for thisaws_base64_encode()
doesn't add null-terminator anymoreaws_base64_compute_encoded_len()
updated to account for thisaws_base64_compute_decoded_len()
math adjusted so that overflow is impossibleBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.