From 524c85d711f9ee26a40d94cb57da92a85befeeea Mon Sep 17 00:00:00 2001 From: Xavier Deguillard Date: Tue, 21 Jan 2020 08:49:24 -0800 Subject: [PATCH] revisionstore: limit delta chain to 1000 entries Summary: We've seen a case where a datapack contains a circular delta chain, causing Mercurial to fall into a infinite loop when trying to read it. Let's fail when the chain is over 1000 entries. Reviewed By: quark-zju Differential Revision: D19458453 fbshipit-source-id: bfa503f7807122eca72cf94418abda161dafa41c --- eden/scm/lib/revisionstore/src/datapack.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eden/scm/lib/revisionstore/src/datapack.rs b/eden/scm/lib/revisionstore/src/datapack.rs index dc26ba39fa..792ffd77cd 100644 --- a/eden/scm/lib/revisionstore/src/datapack.rs +++ b/eden/scm/lib/revisionstore/src/datapack.rs @@ -341,6 +341,13 @@ impl DataStore for DataPack { Some(entry) => entry, }; loop { + // Due to either storage corruption, or wrongly added data to the datapack, we could + // end up in an unbounded loop due to a never ending delta chain. Let's avoid this and + // thus error out if the delta chain is overly long. + if chain.len() > 1000 { + return Err(format_err!("Delta chain too long")); + } + let data_entry = self.read_entry(next_entry.pack_entry_offset())?; chain.push(Delta { data: data_entry.delta()?,