Skip to content

Reject non-mimepart resources in mailparse_msg_* instead of crashing#70

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/msg-funcs-wrong-resource
Open

Reject non-mimepart resources in mailparse_msg_* instead of crashing#70
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/msg-funcs-wrong-resource

Conversation

@iliaal

@iliaal iliaal commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What

Five functions crash the PHP process when handed a resource that is not a mimepart, for example mailparse_msg_parse(tmpfile(), "x").

mailparse_fetch_mimepart_resource expands to zend_fetch_resource, which returns NULL (and raises a TypeError on PHP 8) when the resource type does not match. The functions used the result without checking, so the following call dereferenced NULL: mailparse_msg_parse, mailparse_msg_get_structure, mailparse_msg_get_part_data, mailparse_msg_get_part, and the mailparse_msg_extract_part* family.

The object-method path already NULL-checks the same fetch; only these procedural entry points did not.

Fix

Add if (part == NULL) { RETURN_FALSE; } after each fetch, mirroring the existing guard in mimemsg_get_object. The pending TypeError (PHP 8) or warning (PHP 7) then surfaces cleanly instead of a segfault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant