@@ -7616,6 +7616,7 @@ static int php_openssl_cipher_update(const EVP_CIPHER *cipher_type,
76167616 const char * aad , size_t aad_len , int enc ) /* {{{ */
76177617{
76187618 int i = 0 ;
7619+ size_t outlen = data_len + EVP_CIPHER_block_size (cipher_type );
76197620
76207621 if (mode -> is_single_run_aead && !EVP_CipherUpdate (cipher_ctx , NULL , & i , NULL , (int )data_len )) {
76217622 php_openssl_store_errors ();
@@ -7629,7 +7630,19 @@ static int php_openssl_cipher_update(const EVP_CIPHER *cipher_type,
76297630 return FAILURE ;
76307631 }
76317632
7632- * poutbuf = zend_string_alloc ((int )data_len + EVP_CIPHER_block_size (cipher_type ), 0 );
7633+ #ifdef EVP_CIPH_WRAP_MODE
7634+ if ((EVP_CIPHER_mode (cipher_type )) == EVP_CIPH_WRAP_MODE ) {
7635+ /*
7636+ * RFC 5649 wrap-with-padding rounds the input up to the block size
7637+ * and prepends an integrity block, we reserve one extra block.
7638+ * See EVP_EncryptUpdate(3): wrap mode may write up to
7639+ * inl + cipher_block_size bytes.
7640+ */
7641+ outlen += EVP_CIPHER_block_size (cipher_type );
7642+ }
7643+ #endif
7644+
7645+ * poutbuf = zend_string_alloc (outlen , false);
76337646
76347647 if (!EVP_CipherUpdate (cipher_ctx , (unsigned char * )ZSTR_VAL (* poutbuf ),
76357648 & i , (const unsigned char * )data , (int )data_len )) {
@@ -7641,7 +7654,7 @@ static int php_openssl_cipher_update(const EVP_CIPHER *cipher_type,
76417654 }
76427655 */
76437656 php_openssl_store_errors ();
7644- zend_string_release_ex (* poutbuf , 0 );
7657+ zend_string_release_ex (* poutbuf , false );
76457658 return FAILURE ;
76467659 }
76477660
0 commit comments