Issue #1805 - Improve stack size limits for all targets.

This allows us to use a greater rendering depth for exceedingly-deep DOM trees
in layout, better matching what mainstream browsers are capable of. Note that
for 32-bit Windows the stack size MUST be set to larger than the default or Bad
Things Will Happen™ - we use 1.5 MB for this as a carefully-tuned value.

This needs to be capped specifically for JS use because some JavaScript
obfuscators deliberately trigger stack overflows and would lock up the browser
otherwise as long as there's still stack space to abuse. For web compatibility
we therefore limit this to 2MB in JS only (3x for ASAN) while still allowing
a greater depth for the layout engine.
This commit is contained in:
Moonchild 2022-07-15 11:56:12 +00:00 • committed by roytam1
commit 5ed7e7d56d
4 changed files with 114 additions and 33 deletions

View file

@ -12,7 +12,23 @@
#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))
// Using the same number as Blink's depth limit for 32-bit Windows for consistency.
// Note: This depth of 513 doesn't fit in the default stack of 1 MB, but it
// depth fits when the default is grown by a mere 192 KB.
//
// 32-bit Windows has a different limit compared to 64-bit desktop, because the
// default stack size affects all threads and consumes address space.
//
// Ideally, we'd get rid of this smaller limit and make 32-bit Windows
// capable of working with the Linux/Mac/Win64 number below.
#define MAX_REFLOW_DEPTH 513
#else
// Blink's depth limit from its HTML parser times two. This just about fits
// 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. At the moment