Bug 1500011 - Use CheckedInt more in CalculateBufferSizeForImage. r=smaug, a=RyanVM
authorNika Layzell <nika@thelayzells.com>
Thu, 18 Oct 2018 16:20:03 -0400
changeset 500822 640c972a31a3868bfe328d6071e864559f6fbbeb
parent 500821 d96335858456020e0b28e94e2e6a45fd38b8bfdc
child 500823 5c5acf59e04cae2eb9ee453b42bb9308273676c8
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, RyanVM
bugs1500011
milestone64.0
Bug 1500011 - Use CheckedInt more in CalculateBufferSizeForImage. r=smaug, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D9145
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7863,21 +7863,26 @@ nsresult
 nsContentUtils::CalculateBufferSizeForImage(const uint32_t& aStride,
                                             const IntSize& aImageSize,
                                             const SurfaceFormat& aFormat,
                                             size_t* aMaxBufferSize,
                                             size_t* aUsedBufferSize)
 {
   CheckedInt32 requiredBytes =
     CheckedInt32(aStride) * CheckedInt32(aImageSize.height);
-  if (!requiredBytes.isValid()) {
+
+  CheckedInt32 usedBytes = requiredBytes - aStride +
+    (CheckedInt32(aImageSize.width) * BytesPerPixel(aFormat));
+  if (!usedBytes.isValid()) {
     return NS_ERROR_FAILURE;
   }
+
+  MOZ_ASSERT(requiredBytes.isValid(), "usedBytes valid but not required?");
   *aMaxBufferSize = requiredBytes.value();
-  *aUsedBufferSize = *aMaxBufferSize - aStride + (aImageSize.width * BytesPerPixel(aFormat));
+  *aUsedBufferSize = usedBytes.value();
   return NS_OK;
 }
 
 nsresult
 nsContentUtils::DataTransferItemToImage(const IPCDataTransferItem& aItem,
                                         imgIContainer** aContainer)
 {
   MOZ_ASSERT(aItem.data().type() == IPCDataTransferData::TShmem);