Skip to content
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