Add INT_MAX bounds check before EVP_CipherUpdate in PKCS8/PKCS12 encryption#3043
Merged
Add INT_MAX bounds check before EVP_CipherUpdate in PKCS8/PKCS12 encryption#3043
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3043 +/- ##
==========================================
- Coverage 78.38% 78.37% -0.01%
==========================================
Files 689 689
Lines 121129 121131 +2
Branches 16968 16970 +2
==========================================
- Hits 94948 94938 -10
- Misses 25287 25297 +10
- Partials 894 896 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
justsmth
reviewed
Feb 25, 2026
justsmth
previously approved these changes
Feb 25, 2026
…yption EVP_CipherUpdate takes int for in_len, but add_encrypted_data and PKCS8_marshal_encrypted_private_key pass size_t values. Add a check that in_len + block_size fits in int to prevent silent truncation on 64-bit systems and size_t wraparound on 32-bit systems. This replaces the previous size_t-only overflow check with a unified check that covers both concerns.
justsmth
approved these changes
Mar 3, 2026
torben-hansen
approved these changes
Mar 4, 2026
WillChilds-Klein
pushed a commit
to WillChilds-Klein/aws-lc
that referenced
this pull request
Mar 11, 2026
…yption (aws#3043) ### Issues: N/A ### Description of changes: EVP_CipherUpdate takes int for in_len, but add_encrypted_data and PKCS8_marshal_encrypted_private_key pass size_t values. Add a check that in_len + block_size fits in int to prevent silent truncation on 64-bit systems and size_t wraparound on 32-bit systems. This replaces the previous size_t-only overflow check with a unified check that covers both concerns. ### Call-outs: There are a couple overlapping concerns here and we should make sure the logic is sound. - On a 64-bit system, `size_t` will be 64-bits wide and `int` will be 32-bits wide. This potentially results in a silent truncation due to `EVP_CipherUpdate`'s `int` input. - The Cipher's block-size (128-bits for AES) is added to the input length to determine the output buffer to allocate. This has the potential to overflow the `size_t` used to allocate that buffer (more of a concern for 32-bit systems). ### Testing: How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer? CI By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
nebeid
pushed a commit
to nebeid/aws-lc
that referenced
this pull request
Mar 23, 2026
…yption (aws#3043) ### Issues: N/A ### Description of changes: EVP_CipherUpdate takes int for in_len, but add_encrypted_data and PKCS8_marshal_encrypted_private_key pass size_t values. Add a check that in_len + block_size fits in int to prevent silent truncation on 64-bit systems and size_t wraparound on 32-bit systems. This replaces the previous size_t-only overflow check with a unified check that covers both concerns. ### Call-outs: There are a couple overlapping concerns here and we should make sure the logic is sound. - On a 64-bit system, `size_t` will be 64-bits wide and `int` will be 32-bits wide. This potentially results in a silent truncation due to `EVP_CipherUpdate`'s `int` input. - The Cipher's block-size (128-bits for AES) is added to the input length to determine the output buffer to allocate. This has the potential to overflow the `size_t` used to allocate that buffer (more of a concern for 32-bit systems). ### Testing: How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer? CI By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
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
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.
Issues:
N/A
Description of changes:
EVP_CipherUpdate takes int for in_len, but add_encrypted_data and
PKCS8_marshal_encrypted_private_key pass size_t values. Add a check
that in_len + block_size fits in int to prevent silent truncation on
64-bit systems and size_t wraparound on 32-bit systems. This replaces
the previous size_t-only overflow check with a unified check that
covers both concerns.
Call-outs:
There are a couple overlapping concerns here and we should make sure the logic is sound.
size_twill be 64-bits wide andintwill be 32-bits wide. This potentially results in a silent truncation due toEVP_CipherUpdate'sintinput.size_tused to allocate that buffer (more of a concern for 32-bit systems).Testing:
How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?
CI
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.