From bf77897eca1a0edd0bbd10d889b6ebebf49a7307 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 Feb 2026 09:23:54 +0000 Subject: [PATCH] [Test] Add test cases for MIME_HTML_ONLY with malformed multipart Add tests for edge cases that caused a segfault when multipart/related has no children or contains only non-text content: - alternative-nested-rfc822.eml: multipart/alternative with HTML and related containing only image (no text), plus nested message/rfc822 - alternative-empty-related.eml: multipart/alternative with malformed related that has no proper MIME children These test cases verify the NULL check fix for mp->children. --- .../cases/001_merged/100_general.robot | 12 ++++ .../messages/alternative-empty-related.eml | 21 +++++++ .../messages/alternative-nested-rfc822.eml | 55 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 test/functional/messages/alternative-empty-related.eml create mode 100644 test/functional/messages/alternative-nested-rfc822.eml diff --git a/test/functional/cases/001_merged/100_general.robot b/test/functional/cases/001_merged/100_general.robot index 9456beaa36..6b5dbd0b55 100644 --- a/test/functional/cases/001_merged/100_general.robot +++ b/test/functional/cases/001_merged/100_general.robot @@ -7,6 +7,8 @@ Variables ${RSPAMD_TESTDIR}/lib/vars.py ${GTUBE} ${RSPAMD_TESTDIR}/messages/gtube.eml ${ALT_RELATED} ${RSPAMD_TESTDIR}/messages/alternative-related.eml ${MIXED_RELATED_HTML} ${RSPAMD_TESTDIR}/messages/mixed-related-html-only.eml +${ALT_NESTED_RFC822} ${RSPAMD_TESTDIR}/messages/alternative-nested-rfc822.eml +${ALT_EMPTY_RELATED} ${RSPAMD_TESTDIR}/messages/alternative-empty-related.eml ${SETTINGS_NOSYMBOLS} {symbols_enabled = []} *** Test Cases *** @@ -76,3 +78,13 @@ PARTS DIFFER - multipart/related inside alternative Scan File ${ALT_RELATED} ... Settings={symbols_enabled = [R_PARTS_DIFFER]} Expect Symbol R_PARTS_DIFFER + +HTML ONLY - nested message/rfc822 with alternative + Scan File ${ALT_NESTED_RFC822} + ... Settings={symbols_enabled = [MIME_HTML_ONLY]} + Expect Symbol MIME_HTML_ONLY + +HTML ONLY - malformed related with no children + Scan File ${ALT_EMPTY_RELATED} + ... Settings={symbols_enabled = [MIME_HTML_ONLY]} + Expect Symbol MIME_HTML_ONLY diff --git a/test/functional/messages/alternative-empty-related.eml b/test/functional/messages/alternative-empty-related.eml new file mode 100644 index 0000000000..e4bcd6d156 --- /dev/null +++ b/test/functional/messages/alternative-empty-related.eml @@ -0,0 +1,21 @@ +Return-Path: test@test.com +From: TEST +To: Me +Subject: multipart/alternative with malformed related +MIME-Version: 1.0 +Date: Mon, 01 Jan 2024 00:00:00 +0000 +Message-ID: +Content-Type: multipart/alternative; boundary="=-alt=" + +--=-alt= +Content-Type: text/html; charset="UTF-8" + +HTML only - the sibling related has no valid children + +--=-alt= +Content-Type: multipart/related; boundary="=-related=" + +This is body content but no proper MIME parts inside the related. +The boundary is never used, so children array may be empty/NULL. + +--=-alt=-- diff --git a/test/functional/messages/alternative-nested-rfc822.eml b/test/functional/messages/alternative-nested-rfc822.eml new file mode 100644 index 0000000000..a38007dc70 --- /dev/null +++ b/test/functional/messages/alternative-nested-rfc822.eml @@ -0,0 +1,55 @@ +Return-Path: test@test.com +From: TEST +To: Me +Subject: multipart/alternative with nested rfc822 +MIME-Version: 1.0 +Date: Mon, 01 Jan 2024 00:00:00 +0000 +Message-ID: +Content-Type: multipart/mixed; boundary="=-outer=" + +--=-outer= +Content-Type: multipart/alternative; boundary="=-alt=" + +--=-alt= +Content-Type: text/html; charset="UTF-8" + +HTML only content - the sibling related has no text alternative + +--=-alt= +Content-Type: multipart/related; boundary="=-related=" + +--=-related= +Content-Type: image/png; name="spacer.png" +Content-Transfer-Encoding: base64 + +iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg== + +--=-related=-- + +--=-alt=-- + +--=-outer= +Content-Type: message/rfc822; name="attached.eml" + +Return-Path: inner@test.com +From: Inner +To: Me +Subject: Inner message +MIME-Version: 1.0 +Date: Mon, 01 Jan 2024 00:00:00 +0000 +Message-ID: +Content-Type: multipart/alternative; boundary="=-inner-alt=" + +--=-inner-alt= +Content-Type: text/plain; charset="UTF-8" + +This is the plain text version of the inner message. + +--=-inner-alt= +Content-Type: text/html; charset="UTF-8" + +This is the HTML version of the inner message. + +--=-inner-alt=-- + +--=-outer=-- -- 2.47.3