Segmentation fault when parsing multipart/mixed containing message/rfc822 with multipart/alternative
This script reproduces the issue:
<?php
$data = <<<'EOF'
Content-Type: multipart/mixed;
boundary="MCBoundary=_12210121514003461"
--MCBoundary=_12210121514003461
Content-Type: message/rfc822
Date: Wed, 12 Oct 2022 15:13:59 +0100
Content-Type: multipart/alternative;
boundary="MCBoundary=_12210121514003451"
--MCBoundary=_12210121514003451
Content-Type: text/plain
hello
--MCBoundary=_12210121514003451--
--MCBoundary=_12210121514003461--
EOF;
$resource = mailparse_msg_create();
mailparse_msg_parse($resource, $data);
echo 'OK!';
Running it on version 3.1.3 or 3.1.4 triggers a segmentation fault. it's fine on 3.1.2 however (it causes a Fatal Error because I reduced the example to an incorrect message but it doesn't segfault)
ps: it's different from https://github.com/php/pecl-mail-mailparse/issues/22 that is resolved 3.1.4, maybe it's the same issue as #22 but I'm not sure
We are also hitting this issue when processing email delivery reports, the email being processed has the following type.
Content-Description: Delivery report Content-Type: message/delivery-status
The message includes the original content with the type
Content-Description: Undelivered Message Content-Type: message/rfc822
The missing mime version is triggering the segmentation fault in our mail processor.
Example files for testing attached.
We can also reproduce the error. test_not_working.txt
Please try 92dde0bd6d6658e111e6022ead36eb7d1177caa1
Built the extension from this commit and all our related skipped tests are now green again, thank you!
Thanks for checking
3.1.5 is released