diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 1c86c73ee31a3..593a4ee2fc766 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -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 @@ -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); @@ -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