Bug 1237201 part 3 - Handle Vector OOM in StreamingLexer. r=njn
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 14 Jan 2016 15:19:21 +0100
changeset 279977 2ebafa1c0eee604355b6acbc37270c668f6889f1
parent 279976 96f5d3e2f0d3c0d51379006ab29ae964025b17d3
child 279978 13e1546239391ef5a00058e83a549b8364b911e0
push id70281
push userjandemooij@gmail.com
push dateThu, 14 Jan 2016 14:18:23 +0000
treeherdermozilla-inbound@cdd2accc2d1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1237201
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1237201 part 3 - Handle Vector OOM in StreamingLexer. r=njn
image/StreamingLexer.h
image/test/gtest/TestStreamingLexer.cpp
--- a/image/StreamingLexer.h
+++ b/image/StreamingLexer.h
@@ -311,17 +311,19 @@ public:
       MOZ_ASSERT(mToReadUnbuffered == 0,
                  "Shouldn't be continuing an unbuffered read and a buffered "
                  "read at the same time");
       MOZ_ASSERT(mBuffer.length() < mTransition.Size(),
                  "Buffered more than we needed?");
 
       size_t toRead = std::min(aLength, mTransition.Size() - mBuffer.length());
 
-      mBuffer.append(aInput, toRead);
+      if (!mBuffer.append(aInput, toRead)) {
+        return Some(TerminalState::FAILURE);
+      }
       aInput += toRead;
       aLength -= toRead;
       if (mBuffer.length() != mTransition.Size()) {
         return Nothing();  // Need more input.
       }
 
       // We've buffered everything, so transition to the next state.
       mTransition =
@@ -389,17 +391,19 @@ public:
       return Nothing();  // Need more input.
     }
 
     // If the next state is buffered, buffer what we can and then wait.
     MOZ_ASSERT(mTransition.Buffering() == BufferingStrategy::BUFFERED);
     if (!mBuffer.reserve(mTransition.Size())) {
       return Some(TerminalState::FAILURE);  // Done due to allocation failure.
     }
-    mBuffer.append(aInput, aLength);
+    if (!mBuffer.append(aInput, aLength)) {
+      return Some(TerminalState::FAILURE);
+    }
     return Nothing();  // Need more input.
   }
 
 private:
   Vector<char, InlineBufferSize> mBuffer;
   LexerTransition<State> mTransition;
   size_t mToReadUnbuffered;
 };
--- a/image/test/gtest/TestStreamingLexer.cpp
+++ b/image/test/gtest/TestStreamingLexer.cpp
@@ -50,17 +50,17 @@ DoLexWithUnbuffered(TestState aState, co
                     Vector<char>& aUnbufferedVector)
 {
   switch (aState) {
     case TestState::ONE:
       CheckData(aData, aLength);
       return Transition::ToUnbuffered(TestState::TWO, TestState::UNBUFFERED, 3);
     case TestState::UNBUFFERED:
       EXPECT_TRUE(aLength <= 3);
-      aUnbufferedVector.append(aData, aLength);
+      EXPECT_TRUE(aUnbufferedVector.append(aData, aLength));
       return Transition::ContinueUnbuffered(TestState::UNBUFFERED);
     case TestState::TWO:
       CheckData(aUnbufferedVector.begin(), aUnbufferedVector.length());
       return Transition::To(TestState::THREE, 3);
     case TestState::THREE:
       CheckData(aData, aLength);
       return Transition::TerminateSuccess();
     default: