bug 978847 - check for overflow in nsWindowWatcher coordinate calculations when constraining position. r=roc
authorJonathan Kew <jfkthame@gmail.com>
Thu, 20 Mar 2014 09:46:43 +0000
changeset 174430 39957fc8a90461bac888a58c2d756a19b4cb6974
parent 174429 f26d12bf4252a42f0562ad39911bb238de474a4b
child 174431 9456eb36466e46e21568d20856680f87524878aa
push id41288
push userjkew@mozilla.com
push dateThu, 20 Mar 2014 09:47:15 +0000
treeherdermozilla-inbound@9456eb36466e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs978847
milestone31.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 978847 - check for overflow in nsWindowWatcher coordinate calculations when constraining position. r=roc
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -2006,36 +2006,47 @@ nsWindowWatcher::SizeOpenedDocShellItem(
 
       screen->GetAvailRectDisplayPix(&screenLeft, &screenTop,
                                      &screenWidth, &screenHeight);
 
       if (aSizeSpec.SizeSpecified()) {
         /* Unlike position, force size out-of-bounds check only if
            size actually was specified. Otherwise, intrinsically sized
            windows are broken. */
-        if (height < 100)
+        if (height < 100) {
           height = 100;
-        if (winHeight > screenHeight)
+          winHeight = height + (sizeChromeHeight ? 0 : chromeHeight);
+        }
+        if (winHeight > screenHeight) {
           height = screenHeight - (sizeChromeHeight ? 0 : chromeHeight);
-        if (width < 100)
+        }
+        if (width < 100) {
           width = 100;
-        if (winWidth > screenWidth)
+          winWidth = width + (sizeChromeWidth ? 0 : chromeWidth);
+        }
+        if (winWidth > screenWidth) {
           width = screenWidth - (sizeChromeWidth ? 0 : chromeWidth);
+        }
       }
 
-      if (left + winWidth > screenLeft + screenWidth)
+      if (left + winWidth > screenLeft + screenWidth || left + winWidth < left) {
         left = screenLeft + screenWidth - winWidth;
-      if (left < screenLeft)
+      }
+      if (left < screenLeft) {
         left = screenLeft;
-      if (top + winHeight > screenTop + screenHeight)
+      }
+      if (top + winHeight > screenTop + screenHeight || top + winHeight < top) {
         top = screenTop + screenHeight - winHeight;
-      if (top < screenTop)
+      }
+      if (top < screenTop) {
         top = screenTop;
-      if (top != oldTop || left != oldLeft)
+      }
+      if (top != oldTop || left != oldLeft) {
         positionSpecified = true;
+      }
     }
   }
 
   // size and position the window
 
   if (positionSpecified) {
     treeOwnerAsWin->SetPosition(left * scale, top * scale);
     // moving the window may have changed its scale factor