Bug 864236 - Make multi-MiB allocations in the url-classifier fallible. r=dcamp
This commit is contained in:
@@ -102,11 +102,15 @@ extern PRLogModuleInfo *gUrlClassifierDbServiceLog;
|
||||
#define LOG_ENABLED() (false)
|
||||
#endif
|
||||
|
||||
// Either the return was successful or we call the Reset function.
|
||||
// Used while reading in the store.
|
||||
// Either the return was successful or we call the Reset function (unless we
|
||||
// hit an OOM). Used while reading in the store.
|
||||
#define SUCCESS_OR_RESET(res) \
|
||||
do { \
|
||||
nsresult __rv = res; /* Don't evaluate |res| more than once */ \
|
||||
if (__rv == NS_ERROR_OUT_OF_MEMORY) { \
|
||||
NS_WARNING("SafeBrowsing OOM."); \
|
||||
return __rv; \
|
||||
} \
|
||||
if (NS_FAILED(__rv)) { \
|
||||
NS_WARNING("SafeBrowsing store corrupted or out of date."); \
|
||||
Reset(); \
|
||||
@@ -670,7 +674,7 @@ ByteSliceWrite(nsIOutputStream* aOut, nsTArray<uint32_t>& aData)
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ByteSliceRead(nsIInputStream* aInStream, nsTArray<uint32_t>* aData, uint32_t count)
|
||||
ByteSliceRead(nsIInputStream* aInStream, FallibleTArray<uint32_t>* aData, uint32_t count)
|
||||
{
|
||||
nsTArray<uint8_t> slice1;
|
||||
nsTArray<uint8_t> slice2;
|
||||
@@ -689,7 +693,9 @@ ByteSliceRead(nsIInputStream* aInStream, nsTArray<uint32_t>* aData, uint32_t cou
|
||||
rv = ReadTArray(aInStream, &slice4, count);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aData->SetCapacity(count);
|
||||
if (!aData->SetCapacity(count)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
aData->AppendElement((slice1[i] << 24) | (slice2[i] << 16)
|
||||
@@ -702,7 +708,7 @@ ByteSliceRead(nsIInputStream* aInStream, nsTArray<uint32_t>* aData, uint32_t cou
|
||||
nsresult
|
||||
HashStore::ReadAddPrefixes()
|
||||
{
|
||||
nsTArray<uint32_t> chunks;
|
||||
FallibleTArray<uint32_t> chunks;
|
||||
uint32_t count = mHeader.numAddPrefixes;
|
||||
|
||||
nsresult rv = ByteSliceRead(mInputStream, &chunks, count);
|
||||
@@ -721,9 +727,9 @@ HashStore::ReadAddPrefixes()
|
||||
nsresult
|
||||
HashStore::ReadSubPrefixes()
|
||||
{
|
||||
nsTArray<uint32_t> addchunks;
|
||||
nsTArray<uint32_t> subchunks;
|
||||
nsTArray<uint32_t> prefixes;
|
||||
FallibleTArray<uint32_t> addchunks;
|
||||
FallibleTArray<uint32_t> subchunks;
|
||||
FallibleTArray<uint32_t> prefixes;
|
||||
uint32_t count = mHeader.numSubPrefixes;
|
||||
|
||||
nsresult rv = ByteSliceRead(mInputStream, &addchunks, count);
|
||||
|
||||
Reference in New Issue
Block a user