[PATCH STABLE] filelog: don't crash on invalid copy metadata (issue5748)
Yuya Nishihara
yuya at tcha.org
Fri Dec 1 07:51:09 EST 2017
On Thu, 30 Nov 2017 21:22:10 -0500, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1512094786 18000
> # Thu Nov 30 21:19:46 2017 -0500
> # Branch stable
> # Node ID 5f86d95b1bd8aae2c555d2480aa4ac0d2893d35f
> # Parent 27196b7fc1acfc78711bc4b721fcc68754354c2c
> 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.
I'm not pretty sure if ignoring data corruption is better than the crash.
Are there any integrity concerns?
> --- a/mercurial/filelog.py
> +++ b/mercurial/filelog.py
> @@ -60,10 +60,17 @@ class filelog(revlog.revlog):
> if self.parents(node)[0] != revlog.nullid:
> return False
> t = self.revision(node)
> m = parsemeta(t)[0]
> - if m and "copy" in m:
> - return (m["copy"], revlog.bin(m["copyrev"]))
> + if m:
> + # copy and copyrev occur in pairs. In rare cases due to bugs,
> + # one can occur without the other.
> + try:
> + copy, copyrev = m['copy'], m['copyrev']
> + return copy, revlog.bin(copyrev)
> + except KeyError:
Nit: this except block might be too broad if revlog.bin() weren't a trivial
function.
More information about the Mercurial-devel
mailing list