Commit 6c5b3194 authored by tyoshino@chromium.org's avatar tyoshino@chromium.org

Check if ArrayBuffer allocation in ArrayBufferBuilder is successful.

ArrayBuffer::create may return NULL if allocation fails.

BUG=353966

Review URL: https://codereview.chromium.org/206243002

git-svn-id: svn://svn.chromium.org/blink/trunk@169680 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 745b5472
...@@ -201,18 +201,20 @@ void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse& ...@@ -201,18 +201,20 @@ void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse&
return; return;
} }
if (initialBufferLength < 0) { if (initialBufferLength < 0)
m_rawData = adoptPtr(new ArrayBufferBuilder()); m_rawData = adoptPtr(new ArrayBufferBuilder());
} else { else
m_rawData = adoptPtr(new ArrayBufferBuilder(static_cast<unsigned>(initialBufferLength))); m_rawData = adoptPtr(new ArrayBufferBuilder(static_cast<unsigned>(initialBufferLength)));
// Total size is known. Set m_rawData to ignore overflowed data.
m_rawData->setVariableCapacity(false);
}
if (!m_rawData) { if (!m_rawData || !m_rawData->isValid()) {
failed(FileError::NOT_READABLE_ERR); failed(FileError::NOT_READABLE_ERR);
return; return;
} }
if (initialBufferLength >= 0) {
// Total size is known. Set m_rawData to ignore overflowed data.
m_rawData->setVariableCapacity(false);
}
} }
if (m_client) if (m_client)
......
...@@ -38,7 +38,8 @@ ...@@ -38,7 +38,8 @@
namespace WTF { namespace WTF {
// A utility class to build an ArrayBuffer instance. // A utility class to build an ArrayBuffer instance. Validity must be checked
// by isValid() before using an instance.
class WTF_EXPORT ArrayBufferBuilder { class WTF_EXPORT ArrayBufferBuilder {
// Disallow copying since it's expensive and we don't want code to do it by // Disallow copying since it's expensive and we don't want code to do it by
// accident. // accident.
...@@ -55,6 +56,12 @@ public: ...@@ -55,6 +56,12 @@ public:
m_buffer = ArrayBuffer::create(capacity, 1); m_buffer = ArrayBuffer::create(capacity, 1);
} }
bool isValid() const
{
return m_buffer;
}
// Appending empty data is not allowed.
unsigned append(const char* data, unsigned length); unsigned append(const char* data, unsigned length);
// Returns the accumulated data as an ArrayBuffer instance. If needed, // Returns the accumulated data as an ArrayBuffer instance. If needed,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment