[php-src] Issue #24784: `openssl_pkcs7_read()` / `openssl_cms_read()`: CRLs overwrite certificates in the output array
| From: | adapik | Date: | Tue, 27 Oct 2026 12:56:46 +0000 |
| Subject: | [php-src] Issue #24784: `openssl_pkcs7_read()` / `openssl_cms_read()`: CRLs overwrite certificates in the output array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253237@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/24784
Author: adapik
### Description
openssl_pkcs7_read() and openssl_cms_read() fill the output array with the
certificates first and then with the CRLs. Both loops use their own loop counter as the array index
(add_index_zval(zout, i, ...)), so the CRL loop starts again from index 0. Each CRL
replaces the certificate stored at the same index, and those certificates are lost.
**Reproducer**
```php
<?php
// $pem is a PKCS#7 bundle with one certificate and one CRL, e.g. created with:
// openssl crl2pkcs7 -in crl.pem -certfile cert.pem -out bundle.p7b
$pem = file_get_contents('bundle.p7b');
var_dump(openssl_pkcs7_read($pem, $result));
var_dump(count($result));
foreach ($result as $i => $item) {
echo $i, ': ', strtok($item, "\n"), "\n";
}
```
**Expected result**
```
bool(true)
int(2)
0: -----BEGIN CERTIFICATE-----
1: -----BEGIN X509 CRL-----
```
**Actual result**
```
bool(true)
int(1)
0: -----BEGIN X509 CRL-----
```
The certificate is gone. The same happens in openssl_cms_read() with a CMS bundle.
**PHP Version**
PHP 8.4 and later (the code is the same on 8.5 and master).
### PHP Version
```plain
PHP 8.4.28
```
### Operating System
_No response_