Backed out changeset bc7ca0aabb24 (bug 1134885) for bustage on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2015-02-25 09:05:47 +01:00
Родитель c8ca2853b9
Коммит ce2be86630
6 изменённых файлов: 43 добавлений и 132 удалений

Просмотреть файл

@ -41,9 +41,7 @@ ChunkSet::Set(uint32_t aChunk)
{ {
size_t idx = mChunks.BinaryIndexOf(aChunk); size_t idx = mChunks.BinaryIndexOf(aChunk);
if (idx == nsTArray<uint32_t>::NoIndex) { if (idx == nsTArray<uint32_t>::NoIndex) {
if (!mChunks.InsertElementSorted(aChunk)) { mChunks.InsertElementSorted(aChunk);
return NS_ERROR_OUT_OF_MEMORY;
}
} }
return NS_OK; return NS_OK;
} }
@ -89,9 +87,7 @@ ChunkSet::Remove(const ChunkSet& aOther)
} }
} }
if (!mChunks.SetLength(addIter - mChunks.Elements())) { mChunks.SetLength(addIter - mChunks.Elements());
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -48,7 +48,7 @@ public:
uint32_t *End() { return mChunks.Elements() + mChunks.Length(); } uint32_t *End() { return mChunks.Elements() + mChunks.Length(); }
private: private:
FallibleTArray<uint32_t> mChunks; nsTArray<uint32_t> mChunks;
}; };
} }

Просмотреть файл

@ -123,48 +123,41 @@ namespace safebrowsing {
const uint32_t STORE_MAGIC = 0x1231af3b; const uint32_t STORE_MAGIC = 0x1231af3b;
const uint32_t CURRENT_VERSION = 3; const uint32_t CURRENT_VERSION = 3;
nsresult void
TableUpdate::NewAddPrefix(uint32_t aAddChunk, const Prefix& aHash) TableUpdate::NewAddPrefix(uint32_t aAddChunk, const Prefix& aHash)
{ {
AddPrefix *add = mAddPrefixes.AppendElement(); AddPrefix *add = mAddPrefixes.AppendElement();
if (!add) return NS_ERROR_OUT_OF_MEMORY;
add->addChunk = aAddChunk; add->addChunk = aAddChunk;
add->prefix = aHash; add->prefix = aHash;
return NS_OK;
} }
nsresult void
TableUpdate::NewSubPrefix(uint32_t aAddChunk, const Prefix& aHash, uint32_t aSubChunk) TableUpdate::NewSubPrefix(uint32_t aAddChunk, const Prefix& aHash, uint32_t aSubChunk)
{ {
SubPrefix *sub = mSubPrefixes.AppendElement(); SubPrefix *sub = mSubPrefixes.AppendElement();
if (!sub) return NS_ERROR_OUT_OF_MEMORY;
sub->addChunk = aAddChunk; sub->addChunk = aAddChunk;
sub->prefix = aHash; sub->prefix = aHash;
sub->subChunk = aSubChunk; sub->subChunk = aSubChunk;
return NS_OK;
} }
nsresult void
TableUpdate::NewAddComplete(uint32_t aAddChunk, const Completion& aHash) TableUpdate::NewAddComplete(uint32_t aAddChunk, const Completion& aHash)
{ {
AddComplete *add = mAddCompletes.AppendElement(); AddComplete *add = mAddCompletes.AppendElement();
if (!add) return NS_ERROR_OUT_OF_MEMORY;
add->addChunk = aAddChunk; add->addChunk = aAddChunk;
add->complete = aHash; add->complete = aHash;
return NS_OK;
} }
nsresult void
TableUpdate::NewSubComplete(uint32_t aAddChunk, const Completion& aHash, uint32_t aSubChunk) TableUpdate::NewSubComplete(uint32_t aAddChunk, const Completion& aHash, uint32_t aSubChunk)
{ {
SubComplete *sub = mSubCompletes.AppendElement(); SubComplete *sub = mSubCompletes.AppendElement();
if (!sub) return NS_ERROR_OUT_OF_MEMORY;
sub->addChunk = aAddChunk; sub->addChunk = aAddChunk;
sub->complete = aHash; sub->complete = aHash;
sub->subChunk = aSubChunk; sub->subChunk = aSubChunk;
return NS_OK;
} }
HashStore::HashStore(const nsACString& aTableName, nsIFile* aStoreDir) HashStore::HashStore(const nsACString& aTableName, nsIFile* aStoreDir)
: mTableName(aTableName) : mTableName(aTableName)
, mStoreDirectory(aStoreDir) , mStoreDirectory(aStoreDir)

Просмотреть файл

@ -39,28 +39,18 @@ public:
// Throughout, uint32_t aChunk refers only to the chunk number. Chunk data is // Throughout, uint32_t aChunk refers only to the chunk number. Chunk data is
// stored in the Prefix structures. // stored in the Prefix structures.
nsresult NewAddChunk(uint32_t aChunk) { void NewAddChunk(uint32_t aChunk) { mAddChunks.Set(aChunk); }
return mAddChunks.Set(aChunk); void NewSubChunk(uint32_t aChunk) { mSubChunks.Set(aChunk); }
} NS_WARN_UNUSED_RESULT;
nsresult NewSubChunk(uint32_t aChunk) { void NewAddExpiration(uint32_t aChunk) { mAddExpirations.Set(aChunk); }
return mSubChunks.Set(aChunk); void NewSubExpiration(uint32_t aChunk) { mSubExpirations.Set(aChunk); }
} NS_WARN_UNUSED_RESULT;
nsresult NewAddExpiration(uint32_t aChunk) { void NewAddPrefix(uint32_t aAddChunk, const Prefix& aPrefix);
return mAddExpirations.Set(aChunk); void NewSubPrefix(uint32_t aAddChunk, const Prefix& aPrefix, uint32_t aSubChunk);
} NS_WARN_UNUSED_RESULT;
nsresult NewSubExpiration(uint32_t aChunk) { void NewAddComplete(uint32_t aChunk, const Completion& aCompletion);
return mSubExpirations.Set(aChunk); void NewSubComplete(uint32_t aAddChunk, const Completion& aCompletion,
} NS_WARN_UNUSED_RESULT; uint32_t aSubChunk);
nsresult NewAddPrefix(uint32_t aAddChunk,
const Prefix& aPrefix) NS_WARN_UNUSED_RESULT;
nsresult NewSubPrefix(uint32_t aAddChunk,
const Prefix& aPrefix,
uint32_t aSubChunk) NS_WARN_UNUSED_RESULT;
nsresult NewAddComplete(uint32_t aChunk,
const Completion& aCompletion) NS_WARN_UNUSED_RESULT;
nsresult NewSubComplete(uint32_t aAddChunk,
const Completion& aCompletion,
uint32_t aSubChunk) NS_WARN_UNUSED_RESULT;
void SetLocalUpdate(void) { mLocalUpdate = true; } void SetLocalUpdate(void) { mLocalUpdate = true; }
bool IsLocalUpdate(void) { return mLocalUpdate; } bool IsLocalUpdate(void) { return mLocalUpdate; }

Просмотреть файл

@ -27,8 +27,6 @@ namespace safebrowsing {
// Updates will fail if fed chunks larger than this // Updates will fail if fed chunks larger than this
const uint32_t MAX_CHUNK_SIZE = (1024 * 1024); const uint32_t MAX_CHUNK_SIZE = (1024 * 1024);
// Updates will fail if the total number of touched chunks is larger than this
const uint32_t MAX_CHUNK_RANGE = 1000000;
const uint32_t DOMAIN_SIZE = 4; const uint32_t DOMAIN_SIZE = 4;
@ -173,20 +171,11 @@ ProtocolParser::ProcessExpirations(const nsCString& aLine)
while (begin != end) { while (begin != end) {
uint32_t first, last; uint32_t first, last;
if (ParseChunkRange(begin, end, &first, &last)) { if (ParseChunkRange(begin, end, &first, &last)) {
if (last < first) return NS_ERROR_FAILURE;
if (last - first > MAX_CHUNK_RANGE) return NS_ERROR_FAILURE;
for (uint32_t num = first; num <= last; num++) { for (uint32_t num = first; num <= last; num++) {
if (aLine[0] == 'a') { if (aLine[0] == 'a')
nsresult rv = mTableUpdate->NewAddExpiration(num); mTableUpdate->NewAddExpiration(num);
if (NS_FAILED(rv)) { else
return rv; mTableUpdate->NewSubExpiration(num);
}
} else {
nsresult rv = mTableUpdate->NewSubExpiration(num);
if (NS_FAILED(rv)) {
return rv;
}
}
} }
} else { } else {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -237,31 +226,18 @@ ProtocolParser::ProcessChunkControl(const nsCString& aLine)
LOG(("Processing digest256 data")); LOG(("Processing digest256 data"));
mChunkState.type = (command == 'a') ? CHUNK_ADD_DIGEST : CHUNK_SUB_DIGEST; mChunkState.type = (command == 'a') ? CHUNK_ADD_DIGEST : CHUNK_SUB_DIGEST;
} }
nsresult rv;
switch (mChunkState.type) { switch (mChunkState.type) {
case CHUNK_ADD: case CHUNK_ADD:
rv = mTableUpdate->NewAddChunk(mChunkState.num); mTableUpdate->NewAddChunk(mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
break; break;
case CHUNK_SUB: case CHUNK_SUB:
rv = mTableUpdate->NewSubChunk(mChunkState.num); mTableUpdate->NewSubChunk(mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
break; break;
case CHUNK_ADD_DIGEST: case CHUNK_ADD_DIGEST:
rv = mTableUpdate->NewAddChunk(mChunkState.num); mTableUpdate->NewAddChunk(mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
break; break;
case CHUNK_SUB_DIGEST: case CHUNK_SUB_DIGEST:
rv = mTableUpdate->NewSubChunk(mChunkState.num); mTableUpdate->NewSubChunk(mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
break; break;
} }
@ -347,18 +323,12 @@ ProtocolParser::ProcessPlaintextChunk(const nsACString& aChunk)
if (mChunkState.hashSize == COMPLETE_SIZE) { if (mChunkState.hashSize == COMPLETE_SIZE) {
Completion hash; Completion hash;
hash.FromPlaintext(line, mCryptoHash); hash.FromPlaintext(line, mCryptoHash);
nsresult rv = mTableUpdate->NewAddComplete(mChunkState.num, hash); mTableUpdate->NewAddComplete(mChunkState.num, hash);
if (NS_FAILED(rv)) {
return rv;
}
} else { } else {
NS_ASSERTION(mChunkState.hashSize == 4, "Only 32- or 4-byte hashes can be used for add chunks."); NS_ASSERTION(mChunkState.hashSize == 4, "Only 32- or 4-byte hashes can be used for add chunks.");
Prefix hash; Prefix hash;
hash.FromPlaintext(line, mCryptoHash); hash.FromPlaintext(line, mCryptoHash);
nsresult rv = mTableUpdate->NewAddPrefix(mChunkState.num, hash); mTableUpdate->NewAddPrefix(mChunkState.num, hash);
if (NS_FAILED(rv)) {
return rv;
}
} }
} else { } else {
nsCString::const_iterator begin, iter, end; nsCString::const_iterator begin, iter, end;
@ -376,18 +346,12 @@ ProtocolParser::ProcessPlaintextChunk(const nsACString& aChunk)
if (mChunkState.hashSize == COMPLETE_SIZE) { if (mChunkState.hashSize == COMPLETE_SIZE) {
Completion hash; Completion hash;
hash.FromPlaintext(Substring(iter, end), mCryptoHash); hash.FromPlaintext(Substring(iter, end), mCryptoHash);
nsresult rv = mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num); mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
} else { } else {
NS_ASSERTION(mChunkState.hashSize == 4, "Only 32- or 4-byte hashes can be used for add chunks."); NS_ASSERTION(mChunkState.hashSize == 4, "Only 32- or 4-byte hashes can be used for add chunks.");
Prefix hash; Prefix hash;
hash.FromPlaintext(Substring(iter, end), mCryptoHash); hash.FromPlaintext(Substring(iter, end), mCryptoHash);
nsresult rv = mTableUpdate->NewSubPrefix(addChunk, hash, mChunkState.num); mTableUpdate->NewSubPrefix(addChunk, hash, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
} }
} }
} }
@ -454,10 +418,7 @@ ProtocolParser::ProcessDigestAdd(const nsACString& aChunk)
Completion hash; Completion hash;
hash.Assign(Substring(aChunk, start, COMPLETE_SIZE)); hash.Assign(Substring(aChunk, start, COMPLETE_SIZE));
start += COMPLETE_SIZE; start += COMPLETE_SIZE;
nsresult rv = mTableUpdate->NewAddComplete(mChunkState.num, hash); mTableUpdate->NewAddComplete(mChunkState.num, hash);
if (NS_FAILED(rv)) {
return rv;
}
} }
return NS_OK; return NS_OK;
} }
@ -484,10 +445,7 @@ ProtocolParser::ProcessDigestSub(const nsACString& aChunk)
hash.Assign(Substring(aChunk, start, COMPLETE_SIZE)); hash.Assign(Substring(aChunk, start, COMPLETE_SIZE));
start += COMPLETE_SIZE; start += COMPLETE_SIZE;
nsresult rv = mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num); mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
} }
return NS_OK; return NS_OK;
} }
@ -500,10 +458,7 @@ ProtocolParser::ProcessHostAdd(const Prefix& aDomain, uint8_t aNumEntries,
"ProcessHostAdd should only be called for prefix hashes."); "ProcessHostAdd should only be called for prefix hashes.");
if (aNumEntries == 0) { if (aNumEntries == 0) {
nsresult rv = mTableUpdate->NewAddPrefix(mChunkState.num, aDomain); mTableUpdate->NewAddPrefix(mChunkState.num, aDomain);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK; return NS_OK;
} }
@ -515,10 +470,7 @@ ProtocolParser::ProcessHostAdd(const Prefix& aDomain, uint8_t aNumEntries,
for (uint8_t i = 0; i < aNumEntries; i++) { for (uint8_t i = 0; i < aNumEntries; i++) {
Prefix hash; Prefix hash;
hash.Assign(Substring(aChunk, *aStart, PREFIX_SIZE)); hash.Assign(Substring(aChunk, *aStart, PREFIX_SIZE));
nsresult rv = mTableUpdate->NewAddPrefix(mChunkState.num, hash); mTableUpdate->NewAddPrefix(mChunkState.num, hash);
if (NS_FAILED(rv)) {
return rv;
}
*aStart += PREFIX_SIZE; *aStart += PREFIX_SIZE;
} }
@ -545,10 +497,7 @@ ProtocolParser::ProcessHostSub(const Prefix& aDomain, uint8_t aNumEntries,
memcpy(&addChunk, addChunkStr.BeginReading(), 4); memcpy(&addChunk, addChunkStr.BeginReading(), 4);
addChunk = PR_ntohl(addChunk); addChunk = PR_ntohl(addChunk);
nsresult rv = mTableUpdate->NewSubPrefix(addChunk, aDomain, mChunkState.num); mTableUpdate->NewSubPrefix(addChunk, aDomain, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK; return NS_OK;
} }
@ -569,10 +518,7 @@ ProtocolParser::ProcessHostSub(const Prefix& aDomain, uint8_t aNumEntries,
prefix.Assign(Substring(aChunk, *aStart, PREFIX_SIZE)); prefix.Assign(Substring(aChunk, *aStart, PREFIX_SIZE));
*aStart += PREFIX_SIZE; *aStart += PREFIX_SIZE;
nsresult rv = mTableUpdate->NewSubPrefix(addChunk, prefix, mChunkState.num); mTableUpdate->NewSubPrefix(addChunk, prefix, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
} }
return NS_OK; return NS_OK;
@ -600,10 +546,7 @@ ProtocolParser::ProcessHostAddComplete(uint8_t aNumEntries,
for (uint8_t i = 0; i < aNumEntries; i++) { for (uint8_t i = 0; i < aNumEntries; i++) {
Completion hash; Completion hash;
hash.Assign(Substring(aChunk, *aStart, COMPLETE_SIZE)); hash.Assign(Substring(aChunk, *aStart, COMPLETE_SIZE));
nsresult rv = mTableUpdate->NewAddComplete(mChunkState.num, hash); mTableUpdate->NewAddComplete(mChunkState.num, hash);
if (NS_FAILED(rv)) {
return rv;
}
*aStart += COMPLETE_SIZE; *aStart += COMPLETE_SIZE;
} }
@ -640,10 +583,7 @@ ProtocolParser::ProcessHostSubComplete(uint8_t aNumEntries,
memcpy(&addChunk, addChunkStr.BeginReading(), 4); memcpy(&addChunk, addChunkStr.BeginReading(), 4);
addChunk = PR_ntohl(addChunk); addChunk = PR_ntohl(addChunk);
nsresult rv = mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num); mTableUpdate->NewSubComplete(addChunk, hash, mChunkState.num);
if (NS_FAILED(rv)) {
return rv;
}
} }
return NS_OK; return NS_OK;

Просмотреть файл

@ -669,17 +669,9 @@ nsUrlClassifierDBServiceWorker::CacheCompletions(CacheResultArray *results)
TableUpdate * tu = pParse->GetTableUpdate(resultsPtr->ElementAt(i).table); TableUpdate * tu = pParse->GetTableUpdate(resultsPtr->ElementAt(i).table);
LOG(("CacheCompletion Addchunk %d hash %X", resultsPtr->ElementAt(i).entry.addChunk, LOG(("CacheCompletion Addchunk %d hash %X", resultsPtr->ElementAt(i).entry.addChunk,
resultsPtr->ElementAt(i).entry.ToUint32())); resultsPtr->ElementAt(i).entry.ToUint32()));
rv = tu->NewAddComplete(resultsPtr->ElementAt(i).entry.addChunk, tu->NewAddComplete(resultsPtr->ElementAt(i).entry.addChunk,
resultsPtr->ElementAt(i).entry.complete); resultsPtr->ElementAt(i).entry.complete);
if (NS_FAILED(rv)) { tu->NewAddChunk(resultsPtr->ElementAt(i).entry.addChunk);
// We can bail without leaking here because ForgetTableUpdates
// hasn't been called yet.
return rv;
}
rv = tu->NewAddChunk(resultsPtr->ElementAt(i).entry.addChunk);
if (NS_FAILED(rv)) {
return rv;
}
tu->SetLocalUpdate(); tu->SetLocalUpdate();
updates.AppendElement(tu); updates.AppendElement(tu);
pParse->ForgetTableUpdates(); pParse->ForgetTableUpdates();