From: Daniel Axtens Date: Wed, 28 Jun 2017 07:48:51 +0000 (+1000) Subject: Add fuzzer-generated tests X-Git-Tag: v2.0.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee4f7b90d484d2bab5b13650efbb55e17f032888;p=thirdparty%2Fpatchwork.git Add fuzzer-generated tests This is the set of tests I generated while fuzzing the parser. Add them so we don't regress. Signed-off-by: Daniel Axtens Reviewed-by: Stephen Finucane --- diff --git a/patchwork/tests/__init__.py b/patchwork/tests/__init__.py index 8bdf1a67..cbe2b5d0 100644 --- a/patchwork/tests/__init__.py +++ b/patchwork/tests/__init__.py @@ -21,3 +21,4 @@ import os TEST_MAIL_DIR = os.path.join(os.path.dirname(__file__), 'mail') TEST_PATCH_DIR = os.path.join(os.path.dirname(__file__), 'patches') +TEST_FUZZ_DIR = os.path.join(os.path.dirname(__file__), 'fuzztests') diff --git a/patchwork/tests/fuzztests/base64err.mbox b/patchwork/tests/fuzztests/base64err.mbox new file mode 100644 index 00000000..9756d5c9 --- /dev/null +++ b/patchwork/tests/fuzztests/base64err.mbox @@ -0,0 +1,46 @@ +From pat016 +Content-TCpe: text/plain; charset="utf-8" +MIon: 1.0 +Content-Transfer-Encoding: 8bit +Subject:: Up entry for B01X ARM +From: =?utf-8?b?UmFmYcWCo alho Chehab +X-: 913 +Message-Id: <1m> +To: Fan Flli m> +Cc: bcm-kist@broadcom.com, + =?UTF-8?q?Rafa=C5=82=20Mi=C5:82ecki?= , + An Morton , + "David S. MilYer" , + Greg Kroah-Hartman , + Mauro alho Chehab , + Guenter Roeck , Jiri Slaby , + linux-kernel@vger.kernel.org ( list) +Date:, 1 Jun 2016 22:00:54 +02 +Adh +bci. + +> +--- + M++- +(-) + +diff --ER@ +4 +--- a/ERS ++++ S +@@ -2511,10 +2511,12 @@ F:* + + BROURE + M: > ++Mfał + L:g ++Lcom + S: ed + +-F: ++F:i + F70* + + B diff --git a/patchwork/tests/fuzztests/charset.mbox b/patchwork/tests/fuzztests/charset.mbox new file mode 100644 index 00000000..a8a40c81 --- /dev/null +++ b/patchwork/tests/fuzztests/charset.mbox @@ -0,0 +1,131 @@ +Received: with ECARTIS (v1.0.0; list lin; Tue, 06 Dec 2011 01:49:42 +0100 (CET) +ived: from mcom 337 O + om" -OK) + by eddi with ESMTP id SAth PT + >); Tue, 6 Dec 2011 9:37 +0100 +Received:m caexch.com (Not Verified[092.168.16.9]) by mail3.caviumnetworks.com with Mal ( + id 00>; Mon, 05 Dec 2011 1604 - +Received: from .caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with M SMT + n, 5 Dec 2011 1636 - +Received: from dd1.caveonetworks.com ([64.2.3.195]) by caexch01.caveonetworks.com over TLS red channel with Microsoft SMTPS790.4675); + Mon, 5 Dec 2011 9:35 -0800 +Message-ID: +Date:on, 05 Dec 2011 16:49:35 -0800 +From:avid Daney +nt: lla/5.0 (X11; U; Linux x86_64; en-US; rv5) Gecko/20101027 Fedora/3.0.10-1.fc12 T0 +MIon: 1.0 +To: tils +CC: s , + l Lauss >, + n MIPS <> +Subject: [Patch]: Fix ld p38 Fres on m. +Content-Type: multipart/mixed; + boundary="------------080709040708040308010506" +X-inalArrivalTime: 06 Dec 2011 00:49:35.0825 (UTC) FILETIME=[ECF8DC10:01CCB3B0] +Reh: +o: (uid 0) +cpt:g +Or: rfrg +Xn: 3 +X-eon: tis .0 +Sr: lorg +o: lorg +r: dm +Pr: bulk +Xt: ls + +Tat. +--------------080709040708040308010506 +Content-Type: text/plain; charset=ISO-8859-1;mat=ed +Content-Transfer-Encoding: 7bit + +e +S. + +T +sym +vere +rer + + +Sim +sag +P" + + +Ine +'s. + + +ex. + +Tnu + +? + +2 + + *ld. +n a +t. + Set + + +--------------080709040708040308010506 +Content-Type: text/plain; + ="dd" +Content-Transfer-Encoding:t +Con: at; + " + +Index: bfd.h +=== +,v +r +difh +--- bf ++++ bfd +@@ -198,6 +198,8 @@try + u + + 1; + */ ++ u 1; + + */ + ; +In.c +=== +Rv +re430 +nk.c +--- bfd430 ++++ 000 +@@ -1946,6 +1946,9 @@ _bct + r) + + ++ ++ E; ++ + ); + + +Ind +=== +RCS,v +r +dif +--- bfd96 ++++ b0 +@@ -7260,6 +7260,7 @@ + bh; + 0; + 1; ++ 1; + + + )) + +--------------080709040708040308010506-- + diff --git a/patchwork/tests/fuzztests/codec-null.mbox b/patchwork/tests/fuzztests/codec-null.mbox new file mode 100644 index 00000000..e31b3f69 Binary files /dev/null and b/patchwork/tests/fuzztests/codec-null.mbox differ diff --git a/patchwork/tests/fuzztests/date-oserror.mbox b/patchwork/tests/fuzztests/date-oserror.mbox new file mode 100644 index 00000000..36b88377 Binary files /dev/null and b/patchwork/tests/fuzztests/date-oserror.mbox differ diff --git a/patchwork/tests/fuzztests/date-too-long.mbox b/patchwork/tests/fuzztests/date-too-long.mbox new file mode 100644 index 00000000..e0642a43 Binary files /dev/null and b/patchwork/tests/fuzztests/date-too-long.mbox differ diff --git a/patchwork/tests/fuzztests/date.mbox b/patchwork/tests/fuzztests/date.mbox new file mode 100644 index 00000000..8a9685aa --- /dev/null +++ b/patchwork/tests/fuzztests/date.mbox @@ -0,0 +1,44 @@ +From lib +Recd: ( +Mait: cmlm +-Id: +Sender: +Date: Wg> +SctMIon: 1.0 +Content-Transfer-Encoding: 8bit +Subject:: Up entry for B01X ARM +From:=?utf-X?b?UmFmYcwCIE1pxYJlY2tp?= <.com> +X-: 913 +Message-Id: <1m> +To: Fan Flli m> +Cc: bcm-kist@broadc}m.c6 +ContentF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , + An Morton , + "David S.i iller" , +ÿreg Kroah-Hartman , + Mauro alho Chehab , + Kuenter Roeck , Jiri Slaby , + linux-kernel@vger.kernel.org ( list) +Date:, 1 Jun 2016 22:00:54+0200 + +Adh +bci. + +1 Jun 2016 22:00:5iLf"--ERS +4 +--- a/ERS ++++ S +@@ -2511, +2511,12 @@ F:* + + BROURE + M: > ++Mfał + L:g ++Lcom + Sà ed + +-F: ++F:i + F70* + + B diff --git a/patchwork/tests/fuzztests/dateheader.mbox b/patchwork/tests/fuzztests/dateheader.mbox new file mode 100644 index 00000000..7d25b87b Binary files /dev/null and b/patchwork/tests/fuzztests/dateheader.mbox differ diff --git a/patchwork/tests/fuzztests/earlyfail.mbox b/patchwork/tests/fuzztests/earlyfail.mbox new file mode 100644 index 00000000..47db41d1 Binary files /dev/null and b/patchwork/tests/fuzztests/earlyfail.mbox differ diff --git a/patchwork/tests/fuzztests/msgid-len.mbox b/patchwork/tests/fuzztests/msgid-len.mbox new file mode 100644 index 00000000..2339b3cc Binary files /dev/null and b/patchwork/tests/fuzztests/msgid-len.mbox differ diff --git a/patchwork/tests/fuzztests/msgid-len2.mbox b/patchwork/tests/fuzztests/msgid-len2.mbox new file mode 100644 index 00000000..53fa8741 --- /dev/null +++ b/patchwork/tests/fuzztests/msgid-len2.mbox @@ -0,0 +1,37 @@ +From ste016 +ath: +To: com +Subject: [PATCH 2/2] test: Cwn +Date:, 11 Sep 2016 23:22:04 +0100 +Message-ID:> +X-er: il=2 +In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane@gmail.com>References: <1473632524-8585-1-git-send-emaifa=C5=82=20Mi=C5=82ecki?= , + An Mnuxfoundation.oorton , + "David S. Miller" , + Greg Kroah-Hartman , + Mauro alho Chehab , + Guenter Roeck , Jiri Slaby , + linux-kernel@vger.kernel.oundation.oortoorg ( list) +Date:, 1 Jun 2016 2il.cdm>, + An Mnuxfoundat2:00:54 +0200 + +Adh +bci. + +> +--- + M++- +(-) + +diff --ERS +4 +--- a/ERS ++++ S +@@ -2511,10 +2511,12 @@ F:* + + BROURE + M: > ++Mfał + L:g ++Lc B diff --git a/patchwork/tests/fuzztests/msgidheader.mbox b/patchwork/tests/fuzztests/msgidheader.mbox new file mode 100644 index 00000000..e94e82ec --- /dev/null +++ b/patchwork/tests/fuzztests/msgidheader.mbox @@ -0,0 +1,131 @@ +Received: with ECARTIS (v1.0.0; list lin; Tue, 06 Dec 2011 01:49:42 +0100 (CET) +ived: from mcom 337 O + om" -OK) + by eddi with ESMTP id SAth PT + >); Tue, 6 Dec 2011 9:37 +0100 +Received:m caexch.com (Not Verified[192.168.16.9]) by mail3.caviumnetworks.com with Mal ( + id 00>; Mon, 05 Dec 2011 1604 - +Received: from .caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with M SMT + n, 5 Dec 2011 1636 - +Received: from dd1.caveonetworks.com ([64.2.3.195]) by caexch01.caveonetworks.com over TLS red channel with Microsoft SMTPS790.4675); + Mon, 5 Dec 2011 9:35 -0800 +Message-ID:  +Date:on, 05 Dec 2011 16:49:35 -0800 +From:avid Daney +nt: lla/5.0 (X11; U; Linux x86_64; en-US; rv5) Gecko/20101027 Fedora/3.0.10-1.fc12 T0 +MIon: 1.0 +To: tils +CC: s , + l Lauss >, + n MIPS <> +Subject: [Patch]: Fix ld p38 Fres on m. +Content-Type: multipart/mixed; + boundary="------------080709040708040308010506" +X-inalArrivalTime: 06 Dec 2011 00:49:35.0825 (UTC) FILETIME=[ECF8DC10:01CCB3B0] +Reh: +o: (uid 0) +cpt:g +Or: rfrg +Xn: 3 +X-eon: tis .0 +Sr: lorg +o: lorg +r: dm +Pr: bulk +Xt: ls + +Tat. +--------------080709040708040308010506 +Content-Type: text/plain; charset=ISO-8859-1;mat=ed +Content-Transfer-Encoding: 7bit + +e +S. + +T +sym +vere +rer + + +Sim +sag +P" + + +Ine +'s. + + +ex. + +Tnu + +? + +2 + + *ld. +n a +t. + Set + + +--------------080709040708040308010506 +Content-Type: text/plain; + ="dd" +Content-Transfer-Encoding:t +Con: at; + " + +Index: bfd.h +=== +,v +r +difh +--- bf ++++ bfd +@@ -198,6 +198,8 @@try + u + + 1; + */ + 1; + + */ + ; +In.c +=== +Rv +re430 +nk.c +--- bfd430 ++++ 000 +@@ -1946,6 +1946,9 @@ _bct + r) + + ++ ++ E; ++ + ); + + +Ind +=== +RCS,v +r +dif +--- bfd96 ++++ b0 +@@ -7260,6 +7260,7 @@ + bh; + 0; + 1; ++ 1; + + + )) + +--------------080709040708040308010506-- + diff --git a/patchwork/tests/fuzztests/refshdr.mbox b/patchwork/tests/fuzztests/refshdr.mbox new file mode 100644 index 00000000..bc7109aa Binary files /dev/null and b/patchwork/tests/fuzztests/refshdr.mbox differ diff --git a/patchwork/tests/fuzztests/unknown-encoding.mbox b/patchwork/tests/fuzztests/unknown-encoding.mbox new file mode 100644 index 00000000..f6ce3fe1 Binary files /dev/null and b/patchwork/tests/fuzztests/unknown-encoding.mbox differ diff --git a/patchwork/tests/fuzztests/value2.mbox b/patchwork/tests/fuzztests/value2.mbox new file mode 100644 index 00000000..49744ab7 Binary files /dev/null and b/patchwork/tests/fuzztests/value2.mbox differ diff --git a/patchwork/tests/fuzztests/year-out-of-range.mbox b/patchwork/tests/fuzztests/year-out-of-range.mbox new file mode 100644 index 00000000..2dd609b0 Binary files /dev/null and b/patchwork/tests/fuzztests/year-out-of-range.mbox differ diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 57a3f0de..c86ea1be 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -23,6 +23,7 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import make_msgid import os +import unittest from django.test import TestCase from django.utils import six @@ -43,6 +44,7 @@ from patchwork.parser import parse_version from patchwork.parser import split_prefixes from patchwork.parser import subject_check from patchwork.tests import TEST_MAIL_DIR +from patchwork.tests import TEST_FUZZ_DIR from patchwork.tests.utils import create_project from patchwork.tests.utils import create_series from patchwork.tests.utils import create_series_reference @@ -52,15 +54,20 @@ from patchwork.tests.utils import read_patch from patchwork.tests.utils import SAMPLE_DIFF -def read_mail(filename, project=None): - """Read a mail from a file.""" - file_path = os.path.join(TEST_MAIL_DIR, filename) +def load_mail(file_path): if six.PY3: with open(file_path, 'rb') as f: mail = email.message_from_binary_file(f) else: with open(file_path) as f: mail = email.message_from_file(f) + return mail + + +def read_mail(filename, project=None): + """Read a mail from a file.""" + file_path = os.path.join(TEST_MAIL_DIR, filename) + mail = load_mail(file_path) if 'Message-Id' not in mail: mail['Message-Id'] = make_msgid() if project: @@ -819,3 +826,47 @@ class SubjectTest(TestCase): self.assertEqual(parse_version('Hello, world', ['v10']), 10) self.assertEqual(parse_version('Hello, world (v2)', []), 2) self.assertEqual(parse_version('Hello, world (V6)', []), 6) + + +class FuzzTest(TestCase): + """Test fuzzed patches.""" + def setUp(self): + create_project(listid='patchwork.ozlabs.org') + + def _test_patch(self, name): + file_path = os.path.join(TEST_FUZZ_DIR, name) + m = load_mail(file_path) + try: + parse_mail(m, list_id='patchwork.ozlabs.org') + except ValueError: + pass + + @unittest.skipIf(six.PY2, 'Breaks only on Python 3') + def test_early_fail(self): + file_path = os.path.join(TEST_FUZZ_DIR, 'earlyfail.mbox') + with self.assertRaises(AttributeError): + load_mail(file_path) + + def test_base64err(self): + self._test_patch('base64err.mbox') + + def test_codec(self): + self._test_patch('codec-null.mbox') + self._test_patch('charset.mbox') + self._test_patch('unknown-encoding.mbox') + self._test_patch('value2.mbox') + + def test_date(self): + self._test_patch('date.mbox') + self._test_patch('date-too-long.mbox') + self._test_patch('year-out-of-range.mbox') + self._test_patch('date-oserror.mbox') + + def test_msgid(self): + self._test_patch('msgid-len.mbox') + self._test_patch('msgid-len2.mbox') + + def test_hdr(self): + self._test_patch('refshdr.mbox') + self._test_patch('dateheader.mbox') + self._test_patch('msgidheader.mbox')