Skip to content

Commit 1cb8764

Browse files
committed
Fix [-Wtype-limits] compiler warning on 32bits platforms in Sodium extension
1 parent e8e09b6 commit 1cb8764

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ext/sodium/libsodium.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,10 +1952,12 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt)
19521952
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
19531953
RETURN_THROWS();
19541954
}
1955+
#if SIZEOF_SIZE_T != 4
19551956
if ((unsigned long long) msg_len > (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES) {
19561957
zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0);
19571958
RETURN_THROWS();
19581959
}
1960+
#endif
19591961
ciphertext_len = msg_len + crypto_aead_aes256gcm_ABYTES;
19601962
ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
19611963
if (crypto_aead_aes256gcm_encrypt
@@ -2011,10 +2013,12 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
20112013
if (ciphertext_len < crypto_aead_aes256gcm_ABYTES) {
20122014
RETURN_FALSE;
20132015
}
2016+
#if SIZEOF_SIZE_T != 4
20142017
if (ciphertext_len - crypto_aead_aes256gcm_ABYTES > 16ULL * ((1ULL << 32) - 2ULL)) {
20152018
zend_argument_error(sodium_exception_ce, 1, "is too long");
20162019
RETURN_THROWS();
20172020
}
2021+
#endif
20182022
msg_len = ciphertext_len;
20192023
if (msg_len >= SIZE_MAX) {
20202024
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
@@ -2187,10 +2191,12 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
21872191
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
21882192
RETURN_THROWS();
21892193
}
2194+
#if SIZEOF_SIZE_T != 4
21902195
if ((unsigned long long) msg_len > 64ULL * (1ULL << 32) - 64ULL) {
21912196
zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0);
21922197
RETURN_THROWS();
21932198
}
2199+
#endif
21942200
ciphertext_len = msg_len + crypto_aead_chacha20poly1305_IETF_ABYTES;
21952201
ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
21962202
if (crypto_aead_chacha20poly1305_ietf_encrypt

0 commit comments

Comments
 (0)