From 7b731031339bc3d0345a8fbb66a41f4afa2de3c6 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sun, 15 Sep 2019 00:45:17 +0000 Subject: [PATCH] Add test for mime parsing reportedly crash-inducing message --- .gitattributes | 4 ++++ src/dc_mimeparser.rs | 10 ++++++++++ test-data/message/issue_523.txt | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test-data/message/issue_523.txt diff --git a/.gitattributes b/.gitattributes index 10cbc599e7..47ebe468ce 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,10 @@ # ensures this even if the user has not set core.autocrlf. * text=auto +# This directory contains email messages verbatim, and changing CRLF to +# LF will corrupt them. +test-data/* text=false + # binary files should be detected by git, however, to be sure, you can add them here explicitly *.png binary *.jpg binary diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index b7b109834f..ad2952403a 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -1620,6 +1620,16 @@ mod tests { mailmime_free(mime); } } + + #[test] + fn test_dc_mimeparser_crash() { + let context = dummy_context(); + let raw = include_bytes!("../test-data/message/issue_523.txt"); + let mimeparser = unsafe { dc_mimeparser_parse(&context.ctx, &raw[..]) }; + assert_eq!(mimeparser.subject, None); + assert_eq!(mimeparser.parts.len(), 1); + } + #[test] fn test_mimeparser_with_context() { unsafe { diff --git a/test-data/message/issue_523.txt b/test-data/message/issue_523.txt new file mode 100644 index 0000000000..02b3ec37df --- /dev/null +++ b/test-data/message/issue_523.txt @@ -0,0 +1,21 @@ +Return-Path: +Received: from hq5.merlinux.eu + by hq5.merlinux.eu (Dovecot) with LMTP id yRKOBakcfV1AewAAPzvFDg + ; Sat, 14 Sep 2019 19:00:25 +0200 +Received: from localhost (unknown 7.165.105.24]) + by hq5.merlinux.eu (Postfix) with ESMTPSA id 8D9844E023; + Sat, 14 Sep 2019 19:00:22 +0200 (CEST) +DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=testrun.org; + s=testrun; t=1568480425; + bh=GrziQ9bkbioILHZ1tEn81B53bDgaZK+ENbW4MUBiMUM=; + h=Date:From:To:In-Reply-To:References:Subject:From; + b=eHP/GdBQD1cq601Gaqpz7fd+nQvBJLH7c+bk9KGGC3BKZrRAzehEDOaFlGP2+9oFq + cl+y11nGowenVAw7M5ljjxCpOVy0Aa+atn3e7iZeufgOJPr5Hggg2nPe4qfyP6OmOJ + i9RazyXN1rp4fY7ku9x29g818UL8aWiloJHJ9wqDhMe8OXtIAhJA0gpHDCT1SLgo/a + Kv7/Yj4CA8XS/mRxkbBmpWgcF7SluNjuXU9Npo3aTfjQQ5xSzn72Jsai4n0ppLcQ5k + KobttFy+gkmfQRAe8v7vx51qn82BSsGRlxZWevOB9zit/uk7zb8ZbBqPMeCoWsihRM + LdSqwIpokmYmQ== +Date: Sat, 14 Sep 2019 19:00:13 +0200 +From: lmn +To: abc , def , + jik \ No newline at end of file