Bug 902909: Make some content-controlled allocations fallible in IndexedDB. r=sicking

This commit is contained in:
Kyle Huey 2013-09-16 09:06:11 +08:00
parent 2335177831
commit 9279991419
2 changed files with 10 additions and 3 deletions

View File

@ -55,6 +55,8 @@ using namespace mozilla::dom::indexedDB::ipc;
using mozilla::dom::quota::FileOutputStream;
using mozilla::ErrorResult;
static const mozilla::fallible_t fallible;
BEGIN_INDEXEDDB_NAMESPACE
struct FileHandleData
@ -1133,7 +1135,8 @@ IDBObjectStore::GetStructuredCloneReadInfoFromStatement(
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
nsAutoArrayPtr<char> uncompressed(new char[uncompressedLength]);
nsAutoArrayPtr<char> uncompressed(new (fallible) char[uncompressedLength]);
NS_ENSURE_TRUE(uncompressed, NS_ERROR_OUT_OF_MEMORY);
if (!snappy::RawUncompress(compressed, compressedLength,
uncompressed.get())) {
@ -2969,7 +2972,8 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
// This will hold our compressed data until the end of the method. The
// BindBlobByName function will copy it.
nsAutoArrayPtr<char> compressed(new char[compressedLength]);
nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(uncompressed, uncompressedLength, compressed.get(),
&compressedLength);

View File

@ -30,6 +30,8 @@ using namespace mozilla::dom;
USING_INDEXEDDB_NAMESPACE
USING_QUOTA_NAMESPACE
static const mozilla::fallible_t fallible;
namespace {
// If JS_STRUCTURED_CLONE_VERSION changes then we need to update our major
@ -882,7 +884,8 @@ public:
NS_ENSURE_SUCCESS(rv, rv);
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
nsAutoArrayPtr<char> compressed(new char[compressedLength]);
nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(reinterpret_cast<const char*>(uncompressed),
uncompressedLength, compressed.get(),