php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63542
Patch mailparse-fix_parse.patch revision 2012-11-16 18:09 UTC by vgabor at vgabor dot com

Patch mailparse-fix_parse.patch for mailparse Bug #63542

Patch version 2012-11-16 18:09 UTC

Return to Bug #63542 | Download this patch
Patch Revisions:

Developer: vgabor@vgabor.com

--- mailparse.c.orig	1970-01-01 10:14:21.000000000 +0100
+++ mailparse.c	2012-11-16 16:58:01.000000000 +0000
@@ -1081,6 +1081,8 @@
 		int got = php_stream_read(stream, filebuf, MAILPARSE_BUFSIZ);
 		if (got > 0)	{
 			if (FAILURE == php_mimepart_parse(part, filebuf, got TSRMLS_CC)) {
+				/* We have to destroy the already allocated part, if we not return it */
+				php_mimepart_free(part TSRMLS_CC);
 				RETVAL_FALSE;
 				break;
 			}
--- php_mailparse_mime.c.orig	1970-01-01 10:13:08.000000000 +0100
+++ php_mailparse_mime.c	2012-11-16 17:03:38.000000000 +0000
@@ -722,7 +722,19 @@
 		if (len < bufsize && buf[len] == '\n') {
 			++len;
 			smart_str_appendl(&part->parsedata.workbuf, buf, len);
-			php_mimepart_process_line(part TSRMLS_CC);
+			if (php_mimepart_process_line(part TSRMLS_CC) == FAILURE) {
+				/* php_mimepart_process_line() only returns FAILURE in case the count of children
+				 * have exceeded MAXPARTS and doing so at the very begining, without doing any work.
+				 * It'd do this for all of the following lines, since the exceeded state won't change.
+				 * As no additional work have been done since the last php_mimepart_process_line() call, 
+				 * it is safe to break the loop now not caring about the rest of the code.
+				 * 
+				 * Known issues:
+				 *  - some callers aren't obeying the returned value, but that's in the mailmessage 
+				 *    object which is not documented and seemingly otdated/unfinished anyway
+				 */
+				return FAILURE;
+			};
 			part->parsedata.workbuf.len = 0;
 		} else {
 			smart_str_appendl(&part->parsedata.workbuf, buf, len);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC