From aca47e05a6026c12c768753c87e6ff769ef6bee4 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Sat, 7 Jul 2018 13:22:28 -0500 Subject: Import: Don't copy nulls from emails into git 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 --- lib/PublicInbox/Import.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/PublicInbox/Import.pm') 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", -- cgit v1.2.3-24-ge0c7