Skip to content

Fix for [-Wtype-limits] compiler warning on 32bits platforms in Sodium extension #5304

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/sodium/libsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -1952,10 +1952,12 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt)
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
RETURN_THROWS();
}
#if SIZEOF_SIZE_T != 4
if ((unsigned long long) msg_len > (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES) {
zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0);
RETURN_THROWS();
}
#endif
ciphertext_len = msg_len + crypto_aead_aes256gcm_ABYTES;
ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
if (crypto_aead_aes256gcm_encrypt
Expand Down Expand Up @@ -2011,10 +2013,12 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
if (ciphertext_len < crypto_aead_aes256gcm_ABYTES) {
RETURN_FALSE;
}
#if SIZEOF_SIZE_T != 4
if (ciphertext_len - crypto_aead_aes256gcm_ABYTES > 16ULL * ((1ULL << 32) - 2ULL)) {
zend_argument_error(sodium_exception_ce, 1, "is too long");
RETURN_THROWS();
}
#endif
msg_len = ciphertext_len;
if (msg_len >= SIZE_MAX) {
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
Expand Down Expand Up @@ -2187,10 +2191,12 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
RETURN_THROWS();
}
#if SIZEOF_SIZE_T != 4
if ((unsigned long long) msg_len > 64ULL * (1ULL << 32) - 64ULL) {
zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0);
RETURN_THROWS();
}
#endif
ciphertext_len = msg_len + crypto_aead_chacha20poly1305_IETF_ABYTES;
ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
if (crypto_aead_chacha20poly1305_ietf_encrypt
Expand Down