Skip to content

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

Closed
iliaal wants to merge 1 commit into
masterfrom
fix/msg-funcs-wrong-resource
Closed

Reject non-mimepart resources in mailparse_msg_* instead of crashing#65
iliaal wants to merge 1 commit into
masterfrom
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.

@iliaal

iliaal commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #70, reopened from the fork (iliaal/pecl-mail-mailparse). Branch should not have been pushed to php/ directly.

@iliaal iliaal closed this Jun 19, 2026
@iliaal iliaal deleted the fix/msg-funcs-wrong-resource branch June 19, 2026 13:18
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