Bug 1265342 Part 5c: Add some asserts to ensure ellipse distance field index values are in-bounds. r=dholbert
authorBrad Werth <bwerth@mozilla.com>
Fri, 20 Apr 2018 13:43:36 -0700
changeset 471642 29c3c172caa00b1db0d3ba28ec5200f85ca4cddc
parent 471641 a672de34a369105c2d453d34146fb877911abd61
child 471643 64161554cd20cac22690c5e05962bcb06132896b
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1265342
milestone61.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 1265342 Part 5c: Add some asserts to ensure ellipse distance field index values are in-bounds. r=dholbert MozReview-Commit-ID: CpuWWaLh1CX
layout/generic/nsFloatManager.cpp
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -880,16 +880,19 @@ nsFloatManager::EllipseShapeInfo::Ellips
   const LayoutDeviceIntSize bounds =
     LayoutDevicePixel::FromAppUnitsRounded(radiiPlusShapeMargin,
                                            aAppUnitsPerDevPixel);
   // Since our distance field is computed with a 5x5 neighborhood, but only
   // looks in the negative block and negative inline directions, it is
   // effectively a 3x3 neighborhood. We need to expand our distance field
   // outwards by a further 2 pixels in both axes (on the minimum block edge
   // and the minimum inline edge). We call this edge area the expanded region.
+
+  // Our expansion amounts need to be non-negative for our math to work, but
+  // we don't want to deal with casting them from unsigned ints.
   static const int32_t iExpand = 2;
   static const int32_t bExpand = 2;
   const int32_t iSize = bounds.width + iExpand;
   const int32_t bSize = bounds.height + bExpand;
   auto df = MakeUniqueFallible<dfType[]>(iSize * bSize);
   if (!df) {
     // Without a distance field, we can't reason about the float area.
     return;
@@ -917,16 +920,18 @@ nsFloatManager::EllipseShapeInfo::Ellips
         XInterceptAtY(bInAppUnits, mRadii.width, mRadii.height),
         aAppUnitsPerDevPixel);
 
     // Set iMax in preparation for this block row.
     int32_t iMax = iIntercept;
 
     for (int32_t i = 0; i < iSize; ++i) {
       const int32_t index = i + b * iSize;
+      MOZ_ASSERT(index >= 0 && index < (iSize * bSize),
+                 "Our distance field index should be in-bounds.");
 
       // Handle our three cases, in order.
       if (i < iExpand ||
           bIsInExpandedRegion) {
         // Case 1: Expanded reqion pixel.
         df[index] = MAX_MARGIN_5X;
       } else if (i <= iIntercept) {
         // Case 2: Pixel within the ellipse.
@@ -942,16 +947,21 @@ nsFloatManager::EllipseShapeInfo::Ellips
         // +--+--+--+
         // |11| 7| 5|
         // +--+--+--+
         // |  | 5| X|
         // +--+--+--+
         //
         // X should be set to the minimum of the values of all of the numbered
         // neighbors summed with the value in that chamfer cell.
+        MOZ_ASSERT(index - iSize - 2 >= 0 &&
+                   index - (iSize * 2) - 1 >= 0,
+                   "Our distance field most extreme indices should be "
+                   "in-bounds.");
+
         df[index] = std::min<dfType>(df[index - 1] + 5,
                     std::min<dfType>(df[index - iSize] + 5,
                     std::min<dfType>(df[index - iSize - 1] + 7,
                     std::min<dfType>(df[index - iSize - 2] + 11,
                                      df[index - (iSize * 2) - 1] + 11))));
 
         // Check the df value and see if it's less than or equal to the
         // usedMargin5X value.