diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp
index 52104e4f073..376601f650e 100644
--- a/mozilla/layout/generic/nsFrameSetFrame.cpp
+++ b/mozilla/layout/generic/nsFrameSetFrame.cpp
@@ -959,8 +959,12 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext,
// only borders between s. There are none on the edges (e.g the
// leftmost has no left border).
PRInt32 borderWidth = GetBorderWidth(aPresContext);
+
width -= (mNumCols - 1) * borderWidth;
+ if (width < 0) width = 0;
+
height -= (mNumRows - 1) * borderWidth;
+ if (height < 0) height = 0;
if (!mDrag.mActive && ( (firstTime) ||
( (mRect.width != 0) && (mRect.height != 0) &&
diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp
index 52104e4f073..376601f650e 100644
--- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp
+++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp
@@ -959,8 +959,12 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext,
// only borders between s. There are none on the edges (e.g the
// leftmost has no left border).
PRInt32 borderWidth = GetBorderWidth(aPresContext);
+
width -= (mNumCols - 1) * borderWidth;
+ if (width < 0) width = 0;
+
height -= (mNumRows - 1) * borderWidth;
+ if (height < 0) height = 0;
if (!mDrag.mActive && ( (firstTime) ||
( (mRect.width != 0) && (mRect.height != 0) &&