about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2018-07-07 13:22:28 -0500
committerEric Wong <e@80x24.org>2018-07-07 23:02:13 +0000
commitaca47e05a6026c12c768753c87e6ff769ef6bee4 (patch)
tree5c84328b44e68f9a405f8c3437556177368b7cbc
parentae80a3fdb53d70142624f2691ed8ed84eddda66b (diff)
downloadpublic-inbox-aca47e05a6026c12c768753c87e6ff769ef6bee4.tar.gz
Recently I ran git --git-dir=lkml/git/1.git fsck
and it reported:
> warning in commit 299dbd50b6995c6debe2275f0df984ce697fb4cc: nulInCommit: NULL byte inthe commit object body

Which I found quite scary.  Nulls in the wrong place have a bad tendency
to make programs misbehave.

It turns out someone had placed "=?iso-8859-1?q?=00?=" at the end of
their subject line.  Which is the mime encoding for NULL.  Email::Mime
had correctly decoded the header, and then public-inbox had simply
copied the contents of the header into the subject line of the git
commit.

To prevent that from causing problems replace nulls in such subject
lines with spaces.

Signed-off-by: Eric Biederman <ebiederm@xmission.com>
-rw-r--r--MANIFEST1
-rw-r--r--lib/PublicInbox/Import.pm2
-rw-r--r--t/nulsubject.t33
3 files changed, 36 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 6d2aecee..a2fcae9f 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -177,6 +177,7 @@ t/msgmap.t
 t/msgtime.t
 t/nntp.t
 t/nntpd.t
+t/nulsubject.t
 t/over.t
 t/perf-nntpd.t
 t/perf-threading.t
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 250a2db3..f320c58c 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -405,6 +405,8 @@ sub add {
                 print $w "reset $ref\n" or wfail;
         }
 
+        # Mime decoding can create nulls replace them with spaces to protect git
+        $subject =~ tr/\0/ /;
         utf8::encode($subject);
         print $w "commit $ref\nmark :$commit\n",
                 "author $name <$email> $author_time_raw\n",
diff --git a/t/nulsubject.t b/t/nulsubject.t
new file mode 100644
index 00000000..bb05be85
--- /dev/null
+++ b/t/nulsubject.t
@@ -0,0 +1,33 @@
+# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use warnings;
+use Test::More;
+use File::Temp qw/tempdir/;
+
+use_ok 'PublicInbox::Import';
+use_ok 'PublicInbox::Git';
+my $tmpdir = tempdir('pi-nulsubject-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my $git_dir = "$tmpdir/a.git";
+
+{
+        is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
+        my $git = PublicInbox::Git->new($git_dir);
+        my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
+        $im->add(Email::MIME->create(
+                header => [
+                        From => 'a@example.com',
+                        To => 'b@example.com',
+                        'Content-Type' => 'text/plain',
+                        Subject => ' A subject line with a null =?iso-8859-1?q?=00?= see!',
+                        'Message-ID' => '<null-test.a@example.com>',
+                ],
+                body => "hello world\n",
+        ));
+        $im->done;
+        is(system(qw(git --git-dir), $git_dir, 'fsck', '--strict'), 0, 'git fsck ok');
+}
+
+done_testing();
+
+1;