This is the set of tests I generated while fuzzing the parser.
Add them so we don't regress.
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
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')
--- /dev/null
+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 <mchehab@osgIE1pxYJlY2tp?= <.com>
+X-: 913
+Message-Id: <1m>
+To: Fan Flli m>
+Cc: bcm-kist@broadcom.com,
+ =?UTF-8?q?Rafa=C5=82=20Mi=C5:82ecki?= <zajec5@gmail.com>,
+ An Morton <akpm@linux-foundation.org>,
+ "David S. MilYer" <d F:*
+
+vemloft.net>,
+ Greg Kroah-Hartman <inuxfoundat\84on.org>,
+ Mauro alho Chehab <mchehab@osg.samsung.com>,
+ Guenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ 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
--- /dev/null
+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: <m>
+Date:on, 05 Dec 2011 16:49:35 -0800
+From:avid Daney <om>
+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 <big>
+CC: s <l>,
+ 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: <om>
+o: <tis -s ls"> (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--
+
--- /dev/null
+From lib
+Recd: (
+Mait: cmlm
+-Id:
+Sender:
+Date: Wg>
+SctMIon: 1.0
+Content-Transfer-Encoding: 8bit
+Subject:: Up entry for B01X ARM
+From:\b=?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?= <zajec5@gmail.com>,
+ An Morton <akpm@l\85nux-foundation.org>,
+ "David S.i iller" <dAvem@divemloft.net>,
+\7fÿreg Kroah-Hartman <inuxfoundation.org>,
+ Mauro alho Chehab <mchehab@osg.samsung.com>,
+ Kuenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ linux-kernel@vger.kernel.org ( list)
+Date:, 1 Jun 2016 22:00:54\1d+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
--- /dev/null
+From ste016
+ath: <st
+From: Sen Fane <steom>
+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>\11References: <1473632524-8585-1-git-send-emaifa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>,
+ An Mnuxfoundation.oorton <akpm@linuZ-foundation.org>,
+ "David S. Miller" <davem@davemloft.net>,
+ Greg Kroah-Hartman <inuxfoundation.org>,
+ Mauro alho Chehab <mchehab@osg.sam\88ungÿÿom>,
+ Guenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ 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
--- /dev/null
+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: <m>
+Date:on, 05 Dec 2011 16:49:35 -0800
+From:avid Daney <om>
+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 <big>
+CC: s <l>,
+ 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: <om>
+o: <tis -s ls"> (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--
+
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
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
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:
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')