Bug 1101195 - Update imgData vector length after reading into it. r=jwatt
authorMarkus Stange <mstange@themasta.com>
Wed, 19 Nov 2014 11:51:47 -0500
changeset 216503 750dab541df34b6291e3106652c837841eb2cabc
parent 216502 410efdab71211281d60d3600e64bb737141692a0
child 216504 a6605d017665252c46ea7cee666fc1c29dce154a
push idunknown
push userunknown
push dateunknown
reviewersjwatt
bugs1101195
milestone36.0a1
Bug 1101195 - Update imgData vector length after reading into it. r=jwatt
gfx/thebes/gfxUtils.cpp
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -1194,16 +1194,19 @@ gfxUtils::EncodeSourceSurface(SourceSurf
   if (!imgData.initCapacity(bufSize)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   uint32_t numReadThisTime = 0;
   while ((rv = imgStream->Read(imgData.begin() + imgSize,
                                bufSize - imgSize,
                                &numReadThisTime)) == NS_OK && numReadThisTime > 0)
   {
+    // Update the length of the vector without overwriting the new data.
+    imgData.growByUninitialized(numReadThisTime);
+
     imgSize += numReadThisTime;
     if (imgSize == bufSize) {
       // need a bigger buffer, just double
       bufSize *= 2;
       if (!imgData.resizeUninitialized(bufSize)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }