Bug 1606102 - Don't use putNew in StartupCache::LoadArchive r=froydnj

We can't guarantee uniqueness of the keys here because the file might
be corrupt. So we should check if the key exists and if it does, bail
out.

Differential Revision: https://phabricator.services.mozilla.com/D58387

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Doug Thayer 2019-12-30 18:50:56 +00:00
parent f6604cf751
commit 87af0f0874

View File

@ -319,8 +319,17 @@ Result<Ok, nsresult> StartupCache::LoadArchive() {
}
currentOffset += compressedSize;
if (!mTable.putNew(key, StartupCacheEntry(offset, compressedSize,
uncompressedSize))) {
// We could use mTable.putNew if we knew the file we're loading weren't
// corrupt. However, we don't know that, so check if the key already
// exists. If it does, we know the file must be corrupt.
decltype(mTable)::AddPtr p = mTable.lookupForAdd(key);
if (p) {
return Err(NS_ERROR_UNEXPECTED);
}
if (!mTable.add(
p, key,
StartupCacheEntry(offset, compressedSize, uncompressedSize))) {
return Err(NS_ERROR_UNEXPECTED);
}
}