fix: correct calculation of extensions bitfield size#5719
Merged
WesleyRosenblum merged 8 commits intomainfrom Feb 6, 2026
Merged
fix: correct calculation of extensions bitfield size#5719WesleyRosenblum merged 8 commits intomainfrom
WesleyRosenblum merged 8 commits intomainfrom
Conversation
jmayclin
approved these changes
Feb 3, 2026
maddeleine
approved these changes
Feb 6, 2026
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.
Goal
Reduce the extension bitfield size to the actual size needed to hold all supported extensions
Why
S2N_SUPPORTED_EXTENSIONS_BITFIELD_LENis intended to hold the number of bytes required to assign one bit to each of the TLS extensions supported by s2n-tls. It does this by dividing the number of supported extensions (S2N_SUPPORTED_EXTENSIONS_COUNT) by the size of achartype (sizeof(char)).sizeof(char)always equals 1, so givenS2N_SUPPORTED_EXTENSIONS_COUNT=21, this calculation results in 21 / 1 + 1 = 22 bytes.The actual number of bytes needed to hold 21 extensions would be 21 / (number of bits in a byte) + 1 = 3.
How
Instead of dividing by
sizeof(char)(1), divide byCHAR_BIT(8)Callouts
Since
s2n_connectionhas 3 uses of extension bitfields, that was resulting in a total allocation of 22 * 3 = 66 bytes for each connection. With the updated calculation of 3 bytes, that results in 9 bytes allocated for extensions, a savings of 57 bytes. Therefore, themax_connection_sizeins2n_connection_size_testhas been decreased by 57 bytes.Testing
Existing tests pass
Related
release summary: each connection now uses 57 less bytes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.