diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h
index c99861422c21..9b4b2edab978 100644
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -13,7 +13,32 @@
#error This header/class should only be used within Mozilla code. It should not be used by extensions.
#endif
-#define MAX_REFLOW_DEPTH 200
+#if (defined(XP_WIN) && !defined(HAVE_64BIT_BUILD)) || defined(ANDROID)
+// Blink's magic depth limit from its HTML parser (513) plus as much as fits in the
+// default run-time stack on armv7 Android on Dalvik when using display: block minus
+// a bit just to be sure. The Dalvik default stack crashes at 588. ART can do a few
+// frames more. Using the same number for 32-bit Windows for consistency. Over there,
+// Blink's magic depth of 513 doesn't fit in the default stack of 1 MB, but this magic
+// depth fits when the default is grown by mere 192 KB (tested in 64 KB increments).
+//
+// 32-bit Windows has a different limit compared to 64-bit desktop, because the
+// default stack size affects all threads and consumes address space. Fixing that
+// is bug 1257522.
+//
+// 32-bit Android on ARM already happens to have defaults that are close enough to
+// what makes sense as a temporary measure on Windows, so adjusting the Android
+// stack can be a follow-up. The stack on 64-bit ARM needs adjusting in any case
+// before 64-bit ARM can become tier-1. See bug 1400811.
+//
+// Ideally, we'd get rid of this smaller limit and make 32-bit Windows and Android
+// capable of working with the Linux/Mac/Win64 number below.
+#define MAX_REFLOW_DEPTH 585
+#else
+// Blink's magic depth limit from its HTML parser times two. Also just about fits
+// within the system default runtime stack limit of 8 MB on 64-bit Mac and Linux with
+// display: table-cell.
+#define MAX_REFLOW_DEPTH 1026
+#endif
/* nsIFrame is in the process of being deCOMtaminated, i.e., this file is
eventually going to be eliminated, and all callers will use nsFrame instead.
diff --git a/layout/reftests/bugs/256180-1-ref.html b/layout/reftests/bugs/256180-1-ref.html
new file mode 100644
index 000000000000..c69c53450908
--- /dev/null
+++ b/layout/reftests/bugs/256180-1-ref.html
@@ -0,0 +1,11 @@
+
+
+
+
+ 1026-deep display: table-cell
+
+
+1026-element-deep display: table-cell
+Actual depth (including text leaves): 1027
+
+
diff --git a/layout/reftests/bugs/256180-1.html b/layout/reftests/bugs/256180-1.html
new file mode 100644
index 000000000000..82c1bf4bb490
--- /dev/null
+++ b/layout/reftests/bugs/256180-1.html
@@ -0,0 +1,68 @@
+
+
+
+
+1026-element-deep display: table-cell
+
+
+
+
+1026-element-deep display: table-cell
+
+
diff --git a/layout/reftests/bugs/256180-2-ref.html b/layout/reftests/bugs/256180-2-ref.html
new file mode 100644
index 000000000000..544d7ef5c25f
--- /dev/null
+++ b/layout/reftests/bugs/256180-2-ref.html
@@ -0,0 +1,11 @@
+
+
+
+
+ 585-deep display: table-cell
+
+
+585-element-deep display: table-cell
+Actual depth (including text leaves): 586
+
+
diff --git a/layout/reftests/bugs/256180-2.html b/layout/reftests/bugs/256180-2.html
new file mode 100644
index 000000000000..1887379364d1
--- /dev/null
+++ b/layout/reftests/bugs/256180-2.html
@@ -0,0 +1,68 @@
+
+
+
+
+585-element-deep display: table-cell
+
+
+
+
+585-element-deep display: table-cell
+
+
diff --git a/layout/reftests/bugs/256180-3-ref.html b/layout/reftests/bugs/256180-3-ref.html
new file mode 100644
index 000000000000..d5bec521175c
--- /dev/null
+++ b/layout/reftests/bugs/256180-3-ref.html
@@ -0,0 +1,12 @@
+
+
+
+
+ 1026-deep display: block
+
+
+1026-element-deep display: block
+Actual depth (including text leaves): 1027
+
PASS
+
+
diff --git a/layout/reftests/bugs/256180-3.html b/layout/reftests/bugs/256180-3.html
new file mode 100644
index 000000000000..8b0d6e8c65d6
--- /dev/null
+++ b/layout/reftests/bugs/256180-3.html
@@ -0,0 +1,63 @@
+
+
+
+
+1026-element-deep display: block
+
+
+
+1026-element-deep display: block
+
+
diff --git a/layout/reftests/bugs/256180-4-ref.html b/layout/reftests/bugs/256180-4-ref.html
new file mode 100644
index 000000000000..5b957e3e614b
--- /dev/null
+++ b/layout/reftests/bugs/256180-4-ref.html
@@ -0,0 +1,12 @@
+
+
+
+
+ 585-deep display: block
+
+
+585-element-deep display: block
+Actual depth (including text leaves): 586
+
PASS
+
+
diff --git a/layout/reftests/bugs/256180-4.html b/layout/reftests/bugs/256180-4.html
new file mode 100644
index 000000000000..eabe43ada638
--- /dev/null
+++ b/layout/reftests/bugs/256180-4.html
@@ -0,0 +1,63 @@
+
+
+
+
+585-element-deep display: block
+
+
+
+585-element-deep display: block
+
+
diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list
index e0802fffc69f..c0deccf10af5 100644
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -38,6 +38,17 @@
== 23604-1.html 23604-1-ref.html
== 23604-2.html 23604-2-ref.html
!= 24998-1.html 24998-1-ref.html
+# Debug builds and ASAN builds have larger stack frames, so skipped.
+# 32-bit Windows doesn't have enough run-time stack to deal with the test, so skipped.
+skip-if(isDebugBuild||AddressSanitizer||(winWidget&&(!is64Bit))) == 256180-1.html 256180-1-ref.html
+# Debug builds have larger stack frames, so skipped.
+# 32-bit Windows doesn't have enough run-time stack to deal with the test, so skipped.
+skip-if(isDebugBuild||(winWidget&&(!is64Bit))) == 256180-2.html 256180-2-ref.html
+# Debug builds and ASAN builds have larger stack frames, so skipped.
+# 32-bit Windows doesn't have enough run-time stack to deal with the test, so skipped.
+skip-if(isDebugBuild||AddressSanitizer||(winWidget&&(!is64Bit))) == 256180-3.html 256180-3-ref.html
+# Debug builds have larger stack frames, so skipped.
+skip-if(isDebugBuild) == 256180-4.html 256180-4-ref.html
== 25888-1l.html 25888-1l-ref.html
!= 25888-1l.html 25888-1l-notref.html
== 25888-1r.html 25888-1r-ref.html
diff --git a/layout/tools/reftest/manifest.jsm b/layout/tools/reftest/manifest.jsm
index 78f33226c154..57d3f0db8e23 100644
--- a/layout/tools/reftest/manifest.jsm
+++ b/layout/tools/reftest/manifest.jsm
@@ -463,6 +463,8 @@ function BuildConditionSandbox(aURL) {
sandbox.qtWidget = xr.widgetToolkit == "qt";
sandbox.winWidget = xr.widgetToolkit == "windows";
+ sandbox.is64Bit = xr.is64Bit;
+
// Scrollbars that are semi-transparent. See bug 1169666.
sandbox.transparentScrollbars = xr.widgetToolkit == "gtk3";