]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Add test cases for MIME_HTML_ONLY with malformed multipart
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 5 Feb 2026 09:23:54 +0000 (09:23 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 5 Feb 2026 09:23:54 +0000 (09:23 +0000)
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.

test/functional/cases/001_merged/100_general.robot
test/functional/messages/alternative-empty-related.eml [new file with mode: 0644]
test/functional/messages/alternative-nested-rfc822.eml [new file with mode: 0644]

index 9456beaa3635340ce38dba24d7e2640092ec4474..6b5dbd0b5538e099648fe14d433767741b028f22 100644 (file)
@@ -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 (file)
index 0000000..e4bcd6d
--- /dev/null
@@ -0,0 +1,21 @@
+Return-Path: test@test.com
+From: TEST <test@test.com>
+To: Me <me@me.me>
+Subject: multipart/alternative with malformed related
+MIME-Version: 1.0
+Date: Mon, 01 Jan 2024 00:00:00 +0000
+Message-ID: <alternative-empty-related@test.com>
+Content-Type: multipart/alternative; boundary="=-alt="
+
+--=-alt=
+Content-Type: text/html; charset="UTF-8"
+
+<html><body>HTML only - the sibling related has no valid children</body></html>
+
+--=-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 (file)
index 0000000..a38007d
--- /dev/null
@@ -0,0 +1,55 @@
+Return-Path: test@test.com
+From: TEST <test@test.com>
+To: Me <me@me.me>
+Subject: multipart/alternative with nested rfc822
+MIME-Version: 1.0
+Date: Mon, 01 Jan 2024 00:00:00 +0000
+Message-ID: <alternative-nested-rfc822@test.com>
+Content-Type: multipart/mixed; boundary="=-outer="
+
+--=-outer=
+Content-Type: multipart/alternative; boundary="=-alt="
+
+--=-alt=
+Content-Type: text/html; charset="UTF-8"
+
+<html><body>HTML only content - the sibling related has no text alternative</body></html>
+
+--=-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 <inner@test.com>
+To: Me <me@me.me>
+Subject: Inner message
+MIME-Version: 1.0
+Date: Mon, 01 Jan 2024 00:00:00 +0000
+Message-ID: <inner@test.com>
+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"
+
+<html><body>This is the HTML version of the inner message.</body></html>
+
+--=-inner-alt=--
+
+--=-outer=--