pecl-mail-mailparse icon indicating copy to clipboard operation
pecl-mail-mailparse copied to clipboard

Segmentation fault when parsing multipart/mixed containing message/rfc822 with multipart/alternative

Open mathroc opened this issue 3 years ago • 1 comments

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

mathroc avatar Oct 19 '22 13:10 mathroc

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.

working.txt segfault.txt

odgey avatar Nov 25 '22 09:11 odgey

We can also reproduce the error. test_not_working.txt

fribunet avatar Jan 19 '23 16:01 fribunet

Please try 92dde0bd6d6658e111e6022ead36eb7d1177caa1

remicollet avatar Jul 25 '23 07:07 remicollet

Built the extension from this commit and all our related skipped tests are now green again, thank you!

mathroc avatar Jul 27 '23 07:07 mathroc

Thanks for checking

3.1.5 is released

remicollet avatar Jul 27 '23 12:07 remicollet