# HG changeset patch # User Matt Mackall # Date 2011-12-17 00:23:15 # Node ID 20ae902c43ec5560868b1321c9f156a8c33ef53d # Parent 971c55ce03b81cc71ea33342bc432cc359e79e2a changelog: handle decoding of NULs in extra more carefully (issue3156) Escaped NULs adjacent to [0-7] could be decoded as octal. This hits about 0.24% of changesets with transplant, which stores binary nodes. diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -24,9 +24,20 @@ def _string_escape(text): return text.replace('\0', '\\0') def decodeextra(text): + """ + >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'})) + {'foo': 'bar', 'baz': '\\x002'} + >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(92) + chr(0) + '2'})) + {'foo': 'bar', 'baz': '\\\\\\x002'} + """ extra = {} for l in text.split('\0'): if l: + if '\\0' in l: + # fix up \0 without getting into trouble with \\0 + l = l.replace('\\\\', '\\\\\n') + l = l.replace('\\0', '\0') + l = l.replace('\n', '') k, v = l.decode('string_escape').split(':', 1) extra[k] = v return extra