@@ -1081,7 +1081,7 @@ PHP_FUNCTION(sodium_crypto_sign)
1081
1081
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
1082
1082
RETURN_THROWS ();
1083
1083
}
1084
- if (msg_signed_real_len >= SIZE_MAX || msg_signed_real_len > msg_signed_len ) {
1084
+ if (msg_signed_real_len >= ZSTR_MAX_LEN || msg_signed_real_len > msg_signed_len ) {
1085
1085
zend_string_efree (msg_signed );
1086
1086
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1087
1087
RETURN_THROWS ();
@@ -1113,18 +1113,18 @@ PHP_FUNCTION(sodium_crypto_sign_open)
1113
1113
RETURN_THROWS ();
1114
1114
}
1115
1115
msg_len = msg_signed_len ;
1116
- if (msg_len >= SIZE_MAX ) {
1116
+ if (msg_len >= ZSTR_MAX_LEN ) {
1117
1117
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1118
1118
RETURN_THROWS ();
1119
1119
}
1120
- msg = zend_string_alloc (( size_t ) msg_len , 0 );
1120
+ msg = zend_string_alloc (msg_len , 0 );
1121
1121
if (crypto_sign_open ((unsigned char * ) ZSTR_VAL (msg ), & msg_real_len ,
1122
1122
msg_signed , (unsigned long long ) msg_signed_len ,
1123
1123
publickey ) != 0 ) {
1124
1124
zend_string_efree (msg );
1125
1125
RETURN_FALSE ;
1126
1126
}
1127
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_signed_len ) {
1127
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_signed_len ) {
1128
1128
zend_string_efree (msg );
1129
1129
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1130
1130
RETURN_THROWS ();
@@ -1222,7 +1222,7 @@ PHP_FUNCTION(sodium_crypto_stream)
1222
1222
sodium_remove_param_values_from_backtrace (EG (exception ));
1223
1223
RETURN_THROWS ();
1224
1224
}
1225
- if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX ) {
1225
+ if (ciphertext_len <= 0 || ciphertext_len >= ZSTR_MAX_LEN ) {
1226
1226
zend_argument_error (sodium_exception_ce , 1 , "must be greater than 0" );
1227
1227
RETURN_THROWS ();
1228
1228
}
@@ -1302,7 +1302,7 @@ PHP_FUNCTION(sodium_crypto_stream_xchacha20)
1302
1302
sodium_remove_param_values_from_backtrace (EG (exception ));
1303
1303
RETURN_THROWS ();
1304
1304
}
1305
- if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX ) {
1305
+ if (ciphertext_len <= 0 || ciphertext_len >= ZSTR_MAX_LEN ) {
1306
1306
zend_argument_error (sodium_exception_ce , 1 , "must be greater than 0" );
1307
1307
RETURN_THROWS ();
1308
1308
}
@@ -1619,7 +1619,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
1619
1619
sodium_remove_param_values_from_backtrace (EG (exception ));
1620
1620
RETURN_THROWS ();
1621
1621
}
1622
- if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL ) {
1622
+ if (hash_len <= 0 || hash_len >= ZSTR_MAX_LEN || hash_len > 0x1fffffffe0ULL ) {
1623
1623
zend_argument_error (sodium_exception_ce , 1 , "must be greater than 0" );
1624
1624
RETURN_THROWS ();
1625
1625
}
@@ -1792,7 +1792,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt)
1792
1792
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
1793
1793
RETURN_THROWS ();
1794
1794
}
1795
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
1795
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
1796
1796
ciphertext_real_len > ciphertext_len ) {
1797
1797
zend_string_efree (ciphertext );
1798
1798
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -1854,7 +1854,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
1854
1854
zend_string_efree (msg );
1855
1855
RETURN_FALSE ;
1856
1856
}
1857
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
1857
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
1858
1858
zend_string_efree (msg );
1859
1859
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1860
1860
RETURN_THROWS ();
@@ -1897,12 +1897,12 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_encrypt)
1897
1897
zend_argument_error (sodium_exception_ce , 4 , "must be SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES bytes long" );
1898
1898
RETURN_THROWS ();
1899
1899
}
1900
- if (SIZE_MAX - msg_len <= crypto_aead_aegis128l_ABYTES ) {
1900
+ if (ZSTR_MAX_LEN - msg_len <= crypto_aead_aegis128l_ABYTES ) {
1901
1901
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1902
1902
RETURN_THROWS ();
1903
1903
}
1904
1904
ciphertext_len = msg_len + crypto_aead_aegis128l_ABYTES ;
1905
- ciphertext = zend_string_alloc (( size_t ) ciphertext_len , 0 );
1905
+ ciphertext = zend_string_alloc (ciphertext_len , 0 );
1906
1906
if (crypto_aead_aegis128l_encrypt
1907
1907
((unsigned char * ) ZSTR_VAL (ciphertext ), & ciphertext_real_len , msg ,
1908
1908
(unsigned long long ) msg_len ,
@@ -1911,7 +1911,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_encrypt)
1911
1911
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
1912
1912
RETURN_THROWS ();
1913
1913
}
1914
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
1914
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
1915
1915
ciphertext_real_len > ciphertext_len ) {
1916
1916
zend_string_efree (ciphertext );
1917
1917
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -1969,7 +1969,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_decrypt)
1969
1969
zend_string_efree (msg );
1970
1970
RETURN_FALSE ;
1971
1971
}
1972
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
1972
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
1973
1973
zend_string_efree (msg );
1974
1974
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1975
1975
RETURN_THROWS ();
@@ -2012,12 +2012,12 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_encrypt)
2012
2012
zend_argument_error (sodium_exception_ce , 4 , "must be SODIUM_CRYPTO_AEAD_AEGIS256_KEYBYTES bytes long" );
2013
2013
RETURN_THROWS ();
2014
2014
}
2015
- if (SIZE_MAX - msg_len <= crypto_aead_aegis256_ABYTES ) {
2015
+ if (ZSTR_MAX_LEN - msg_len <= crypto_aead_aegis256_ABYTES ) {
2016
2016
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2017
2017
RETURN_THROWS ();
2018
2018
}
2019
2019
ciphertext_len = msg_len + crypto_aead_aegis256_ABYTES ;
2020
- ciphertext = zend_string_alloc (( size_t ) ciphertext_len , 0 );
2020
+ ciphertext = zend_string_alloc (ciphertext_len , 0 );
2021
2021
if (crypto_aead_aegis256_encrypt
2022
2022
((unsigned char * ) ZSTR_VAL (ciphertext ), & ciphertext_real_len , msg ,
2023
2023
(unsigned long long ) msg_len ,
@@ -2026,7 +2026,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_encrypt)
2026
2026
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
2027
2027
RETURN_THROWS ();
2028
2028
}
2029
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
2029
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
2030
2030
ciphertext_real_len > ciphertext_len ) {
2031
2031
zend_string_efree (ciphertext );
2032
2032
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -2072,19 +2072,19 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_decrypt)
2072
2072
RETURN_FALSE ;
2073
2073
}
2074
2074
msg_len = ciphertext_len ;
2075
- if (msg_len >= SIZE_MAX ) {
2075
+ if (msg_len >= ZSTR_MAX_LEN ) {
2076
2076
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2077
2077
RETURN_THROWS ();
2078
2078
}
2079
- msg = zend_string_alloc (( size_t ) msg_len , 0 );
2079
+ msg = zend_string_alloc (msg_len , 0 );
2080
2080
if (crypto_aead_aegis256_decrypt
2081
2081
((unsigned char * ) ZSTR_VAL (msg ), & msg_real_len , NULL ,
2082
2082
ciphertext , (unsigned long long ) ciphertext_len ,
2083
2083
ad , (unsigned long long ) ad_len , npub , secretkey ) != 0 ) {
2084
2084
zend_string_efree (msg );
2085
2085
RETURN_FALSE ;
2086
2086
}
2087
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
2087
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
2088
2088
zend_string_efree (msg );
2089
2089
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2090
2090
RETURN_THROWS ();
@@ -2126,12 +2126,12 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt)
2126
2126
zend_argument_error (sodium_exception_ce , 4 , "must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes long" );
2127
2127
RETURN_THROWS ();
2128
2128
}
2129
- if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_ABYTES ) {
2129
+ if (ZSTR_MAX_LEN - msg_len <= crypto_aead_chacha20poly1305_ABYTES ) {
2130
2130
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2131
2131
RETURN_THROWS ();
2132
2132
}
2133
2133
ciphertext_len = msg_len + crypto_aead_chacha20poly1305_ABYTES ;
2134
- ciphertext = zend_string_alloc (( size_t ) ciphertext_len , 0 );
2134
+ ciphertext = zend_string_alloc (ciphertext_len , 0 );
2135
2135
if (crypto_aead_chacha20poly1305_encrypt
2136
2136
((unsigned char * ) ZSTR_VAL (ciphertext ), & ciphertext_real_len , msg ,
2137
2137
(unsigned long long ) msg_len ,
@@ -2140,7 +2140,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt)
2140
2140
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
2141
2141
RETURN_THROWS ();
2142
2142
}
2143
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
2143
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
2144
2144
ciphertext_real_len > ciphertext_len ) {
2145
2145
zend_string_efree (ciphertext );
2146
2146
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -2186,7 +2186,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt)
2186
2186
RETURN_FALSE ;
2187
2187
}
2188
2188
msg_len = ciphertext_len ;
2189
- if (msg_len >= SIZE_MAX ) {
2189
+ if (msg_len >= ZSTR_MAX_LEN ) {
2190
2190
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2191
2191
RETURN_THROWS ();
2192
2192
}
@@ -2198,7 +2198,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt)
2198
2198
zend_string_efree (msg );
2199
2199
RETURN_FALSE ;
2200
2200
}
2201
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
2201
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
2202
2202
zend_string_efree (msg );
2203
2203
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2204
2204
RETURN_THROWS ();
@@ -2239,7 +2239,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
2239
2239
zend_argument_error (sodium_exception_ce , 4 , "must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes long" );
2240
2240
RETURN_THROWS ();
2241
2241
}
2242
- if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_IETF_ABYTES ) {
2242
+ if (ZSTR_MAX_LEN - msg_len <= crypto_aead_chacha20poly1305_IETF_ABYTES ) {
2243
2243
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2244
2244
RETURN_THROWS ();
2245
2245
}
@@ -2257,7 +2257,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
2257
2257
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
2258
2258
RETURN_THROWS ();
2259
2259
}
2260
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
2260
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
2261
2261
ciphertext_real_len > ciphertext_len ) {
2262
2262
zend_string_efree (ciphertext );
2263
2263
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -2300,7 +2300,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt)
2300
2300
RETURN_THROWS ();
2301
2301
}
2302
2302
msg_len = ciphertext_len ;
2303
- if (msg_len >= SIZE_MAX ) {
2303
+ if (msg_len >= ZSTR_MAX_LEN ) {
2304
2304
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2305
2305
RETURN_THROWS ();
2306
2306
}
@@ -2320,7 +2320,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt)
2320
2320
zend_string_efree (msg );
2321
2321
RETURN_FALSE ;
2322
2322
}
2323
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
2323
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
2324
2324
zend_string_efree (msg );
2325
2325
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2326
2326
RETURN_THROWS ();
@@ -2362,7 +2362,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt)
2362
2362
zend_argument_error (sodium_exception_ce , 4 , "must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes long" );
2363
2363
RETURN_THROWS ();
2364
2364
}
2365
- if (SIZE_MAX - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES ) {
2365
+ if (ZSTR_MAX_LEN - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES ) {
2366
2366
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2367
2367
RETURN_THROWS ();
2368
2368
}
@@ -2376,7 +2376,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt)
2376
2376
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
2377
2377
RETURN_THROWS ();
2378
2378
}
2379
- if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
2379
+ if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN ||
2380
2380
ciphertext_real_len > ciphertext_len ) {
2381
2381
zend_string_efree (ciphertext );
2382
2382
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
@@ -2422,7 +2422,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt)
2422
2422
RETURN_FALSE ;
2423
2423
}
2424
2424
msg_len = ciphertext_len ;
2425
- if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >= SIZE_MAX ) {
2425
+ if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >= ZSTR_MAX_LEN ) {
2426
2426
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2427
2427
RETURN_THROWS ();
2428
2428
}
@@ -2439,7 +2439,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt)
2439
2439
zend_string_efree (msg );
2440
2440
RETURN_FALSE ;
2441
2441
}
2442
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
2442
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
2443
2443
zend_string_efree (msg );
2444
2444
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2445
2445
RETURN_THROWS ();
@@ -2463,12 +2463,12 @@ PHP_FUNCTION(sodium_bin2hex)
2463
2463
sodium_remove_param_values_from_backtrace (EG (exception ));
2464
2464
RETURN_THROWS ();
2465
2465
}
2466
- if (bin_len >= SIZE_MAX / 2U ) {
2466
+ if (bin_len >= ZSTR_MAX_LEN / 2U ) {
2467
2467
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2468
2468
RETURN_THROWS ();
2469
2469
}
2470
2470
hex_len = bin_len * 2U ;
2471
- hex = zend_string_alloc (( size_t ) hex_len , 0 );
2471
+ hex = zend_string_alloc (hex_len , 0 );
2472
2472
sodium_bin2hex (ZSTR_VAL (hex ), hex_len + 1U , bin , bin_len );
2473
2473
ZSTR_VAL (hex )[hex_len ] = 0 ;
2474
2474
@@ -2501,7 +2501,7 @@ PHP_FUNCTION(sodium_hex2bin)
2501
2501
zend_argument_error (sodium_exception_ce , 1 , "must be a valid hexadecimal string" );
2502
2502
RETURN_THROWS ();
2503
2503
}
2504
- if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len ) {
2504
+ if (bin_real_len >= ZSTR_MAX_LEN || bin_real_len > bin_len ) {
2505
2505
zend_string_efree (bin );
2506
2506
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2507
2507
RETURN_THROWS ();
@@ -2530,7 +2530,7 @@ PHP_FUNCTION(sodium_bin2base64)
2530
2530
zend_argument_error (sodium_exception_ce , 2 , "must be a valid base64 variant identifier" );
2531
2531
RETURN_THROWS ();
2532
2532
}
2533
- if (bin_len >= SIZE_MAX / 4U * 3U - 3U - 1U ) {
2533
+ if (bin_len >= ZSTR_MAX_LEN / 4U * 3U - 3U - 1U ) {
2534
2534
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2535
2535
RETURN_THROWS ();
2536
2536
}
@@ -2573,7 +2573,7 @@ PHP_FUNCTION(sodium_base642bin)
2573
2573
zend_argument_error (sodium_exception_ce , 1 , "must be a valid base64 string" );
2574
2574
RETURN_THROWS ();
2575
2575
}
2576
- if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len ) {
2576
+ if (bin_real_len >= ZSTR_MAX_LEN || bin_real_len > bin_len ) {
2577
2577
zend_string_efree (bin );
2578
2578
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
2579
2579
RETURN_THROWS ();
@@ -3475,7 +3475,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push)
3475
3475
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
3476
3476
RETURN_THROWS ();
3477
3477
}
3478
- if (c_real_len <= 0U || c_real_len >= SIZE_MAX || c_real_len > c_len ) {
3478
+ if (c_real_len <= 0U || c_real_len >= ZSTR_MAX_LEN || c_real_len > c_len ) {
3479
3479
zend_string_efree (c );
3480
3480
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
3481
3481
RETURN_THROWS ();
@@ -3559,7 +3559,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull)
3559
3559
zend_string_efree (msg );
3560
3560
RETURN_FALSE ;
3561
3561
}
3562
- if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len ) {
3562
+ if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len ) {
3563
3563
zend_string_efree (msg );
3564
3564
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
3565
3565
RETURN_THROWS ();
0 commit comments