Skip to content

Commit 644944a

Browse files
committed
Possible fix for Wtype-limits on 32bits platforms in Sodium extension
1 parent 8af5625 commit 644944a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ext/sodium/libsodium.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,8 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt)
19521952
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
19531953
RETURN_THROWS();
19541954
}
1955-
if ((unsigned long long) msg_len > (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES) {
1955+
/* No-op to fix [-Wtype-limits] on 32bits platforms */
1956+
if ((unsigned long long) msg_len * 1ULL > (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
}
@@ -2011,7 +2012,8 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
20112012
if (ciphertext_len < crypto_aead_aes256gcm_ABYTES) {
20122013
RETURN_FALSE;
20132014
}
2014-
if (ciphertext_len - crypto_aead_aes256gcm_ABYTES > 16ULL * ((1ULL << 32) - 2ULL)) {
2015+
/* No-op to fix [-Wtype-limits] on 32bits platforms */
2016+
if (ciphertext_len - crypto_aead_aes256gcm_ABYTES + 0ULL > 16ULL * ((1ULL << 32) - 2ULL)) {
20152017
zend_argument_error(sodium_exception_ce, 1, "is too long");
20162018
RETURN_THROWS();
20172019
}
@@ -2187,7 +2189,8 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
21872189
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
21882190
RETURN_THROWS();
21892191
}
2190-
if ((unsigned long long) msg_len > 64ULL * (1ULL << 32) - 64ULL) {
2192+
/* No-op to fix [-Wtype-limits] on 32bits platforms */
2193+
if ((unsigned long long) msg_len * 1ULL > 64ULL * (1ULL << 32) - 64ULL) {
21912194
zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0);
21922195
RETURN_THROWS();
21932196
}

0 commit comments

Comments
 (0)