Commit messages may not contain NUL characters; in practice,
Debian changelogs sometimes do, usually as the result of
incorrectly used encoding for non-ASCII personal names.
As a safety net, delete all NULs from the output of dpkg-parsechangelog
before parsing it, so that they don’t get fed into Git or anything else
further in the processing.
Closes: #981340
if cmd.returncode:
raise ParseChangeLogError("Failed to parse changelog. "
"dpkg-parsechangelog said:\n%s" % stderr.decode().strip())
- return stdout.decode()
+ return stdout.decode().replace('\0', '')
def _parse(self):
"""Parse a changelog based on the already read contents."""
self.assertEquals(cl.email, 'agx@sigxcpu.org')
+class TestEncoding(unittest.TestCase):
+ def test_nul(self):
+ """Test we remove NUL characters from strings when parsing (#981340)"""
+ changes = """git-buildpackage (0.9.2) unstable; urgency=low
+
+ * List of ch\0nges
+
+ -- User N\0me <agx@sigxcpu.org> Sun, 12 Nov 2017 19:00:00 +0200
+"""
+ cl = ChangeLog(changes)
+ self.assertEquals(cl.author, 'User Nme')
+ self.assertEquals(cl.email, 'agx@sigxcpu.org')
+ self.assertEquals('\0' in cl.get_changes(), False)
+
+
@skip_without_cmd('debchange')
class Test(unittest.TestCase):
def setUp(self):