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
This commit is contained in:
Xavier Deguillard 2020-01-21 08:49:24 -08:00 committed by Facebook Github Bot
parent b863b99cd2
commit 524c85d711

View File

@ -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()?,