 -                if (remainingLogicalHeight - footHeight < childLogicalHeight) {
 +
 +        for (int r = 0; r < totalRows; ++r) {
-+            int rowLogicalOffset = m_rowPos[r] + pageOffset;
-+            int remainingLogicalHeight = pageLogicalHeight - layoutState->pageLogicalOffset(rowLogicalOffset) % pageLogicalHeight;
++            m_rowPos[r] += pageOffset;
++            int remainingLogicalHeight = pageLogicalHeight - layoutState->pageLogicalOffset(m_rowPos[r]) % pageLogicalHeight;
++            int availableHeight = remainingLogicalHeight - footHeight - vspacing;
 +
 +            for (int c = 0; c < nEffCols; c++) {
 +                CellStruct& cs = cellAt(r, c);

             } else {
                 rHeight = m_rowPos[rindx + cell->rowSpan()] - m_rowPos[rindx] - vspacing;
             }
@@ -1253,4 +1260,4 @@ bool RenderTableSection::nodeAtPoint(const HitTestRequest& request, HitTestResul
 
 }
 
-} // namespace WebCore
+} // namespace WebCore
\ No newline at end of file
-- 
1.7.6.1


+                    continue;
+
+                int cellRequiredHeight = cell->contentLogicalHeight() + cell->paddingTop(false) + cell->paddingBottom(false);
+                int requiredHeight = max(logicalRowHeights[r], cellRequiredHeight);
+                if (requiredHeight >= availableHeight) {
                     pageOffset += remainingLogicalHeight + headHeight;
+                    if (requiredHeight > availableHeight) {
+                        m_rowPos[r] += remainingLogicalHeight + headHeight;
+                    }
+                    break;
                 }
             }
-            m_rowPos[r] += pageOffset;
         }
         m_rowPos[totalRows] += pageOffset;
     }
@@ -525,11 +540,7 @@ int RenderTableSection::layoutRows(int toAdd, int headHeight, int footHeight)
         if (RenderTableRow* rowRenderer = m_grid[r].rowRenderer) {
             rowRenderer->setLocation(0, m_rowPos[r]);
             rowRenderer->setLogicalWidth(logicalWidth());
