MANIFEST | 1 + lib/PublicInbox/Import.pm | 2 ++ t/nulsubject.t | 33 +++++++++++++++++++++++++++++++++ diff --git a/MANIFEST b/MANIFEST index 6d2aecee23c6e6dac765c481c5efff8b24b7aef4..a2fcae9f4a21a646c554e2749cd503952eabc5ce 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 250a2db31e979054c94df5a0e1dd6ca2d8a5f883..f320c58c6b575023ec94dfcd12e8cbd6910f7af4 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -405,6 +405,8 @@ unless ($parent) { 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 0000000000000000000000000000000000000000..bb05be8589e71ceda4875e7f88cc6cec3bfe36db --- /dev/null +++ b/t/nulsubject.t @@ -0,0 +1,33 @@ +# Copyright (C) 2016-2018 all contributors +# License: AGPL-3.0+ +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' => '', + ], + body => "hello world\n", + )); + $im->done; + is(system(qw(git --git-dir), $git_dir, 'fsck', '--strict'), 0, 'git fsck ok'); +} + +done_testing(); + +1;