Skip to content

Commit cd8c9b0

Browse files
committed
Fix outlen for openssl function
Even though datalen can't be over int, outlen can.
1 parent 2301608 commit cd8c9b0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ext/openssl/openssl.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -5303,7 +5303,8 @@ PHP_FUNCTION(openssl_encrypt)
53035303
size_t data_len, method_len, password_len, iv_len = 0, max_iv_len;
53045304
const EVP_CIPHER *cipher_type;
53055305
EVP_CIPHER_CTX cipher_ctx;
5306-
int i=0, outlen, keylen;
5306+
int i=0, keylen;
5307+
size_t outlen;
53075308
zend_string *outbuf;
53085309
unsigned char *key;
53095310
zend_bool free_iv;
@@ -5334,7 +5335,7 @@ PHP_FUNCTION(openssl_encrypt)
53345335
}
53355336
free_iv = php_openssl_validate_iv(&iv, &iv_len, max_iv_len);
53365337

5337-
outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
5338+
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
53385339
outbuf = zend_string_alloc(outlen, 0);
53395340

53405341
EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL);
@@ -5386,7 +5387,8 @@ PHP_FUNCTION(openssl_decrypt)
53865387
size_t data_len, method_len, password_len, iv_len = 0;
53875388
const EVP_CIPHER *cipher_type;
53885389
EVP_CIPHER_CTX cipher_ctx;
5389-
int i, outlen, keylen;
5390+
int i, keylen;
5391+
size_t outlen;
53905392
zend_string *outbuf;
53915393
unsigned char *key;
53925394
zend_string *base64_str = NULL;
@@ -5410,7 +5412,7 @@ PHP_FUNCTION(openssl_decrypt)
54105412
}
54115413

54125414
if (!(options & OPENSSL_RAW_DATA)) {
5413-
base64_str = php_base64_decode((unsigned char*)data, (int)data_len);
5415+
base64_str = php_base64_decode((unsigned char*)data, data_len);
54145416
if (!base64_str) {
54155417
php_error_docref(NULL, E_WARNING, "Failed to base64 decode the input");
54165418
RETURN_FALSE;
@@ -5430,7 +5432,7 @@ PHP_FUNCTION(openssl_decrypt)
54305432

54315433
free_iv = php_openssl_validate_iv(&iv, &iv_len, EVP_CIPHER_iv_length(cipher_type));
54325434

5433-
outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
5435+
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
54345436
outbuf = zend_string_alloc(outlen, 0);
54355437

54365438
EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL);

0 commit comments

Comments
 (0)