filelog: don't crash on invalid copy metadata (issue5748) stable 4.6
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 30 Nov 2017 21:19:46 -0500
branchstable
changeset 37833 6614cac550ae
parent 37832 6169d95dce3b
child 37834 ed6808cfb116
filelog: don't crash on invalid copy metadata (issue5748) "copy" and "copyrev" are both supposed to appear next to each other. However, a user report demonstrated a crash that indicates that something in the wild is producing "copy" without "copyrev" (probably `hg convert`). While we should definitely fix the source of the bad metadata, the bad code causing the crash is already in the wild and who knows how many repositories are impacted. So let's be more defensive when accessing the file revision metadata.
mercurial/filelog.py
--- a/mercurial/filelog.py	Mon Apr 30 15:32:11 2018 -0700
+++ b/mercurial/filelog.py	Thu Nov 30 21:19:46 2017 -0500
@@ -135,7 +135,9 @@
             return False
         t = self.revision(node)
         m = revlog.parsemeta(t)[0]
-        if m and "copy" in m:
+        # copy and copyrev occur in pairs. In rare cases due to bugs,
+        # one can occur without the other.
+        if m and "copy" in m and "copyrev" in m:
             return (m["copy"], revlog.bin(m["copyrev"]))
         return False