Commit 6399068
committed
Fix GH-15869: Stack overflow in zend_array_destroy with deeply nested arrays
When zend_array_destroy recurses through rc_dtor_func for nested arrays,
deeply nested structures (200K+ levels) overflow the C stack.
Guard zend_array_destroy with zend_call_stack_overflowed(). When the
stack is near its limit, switch to zend_array_destroy_iterative() which
uses tail-call elimination for linear chains and a heap-allocated work
list for sibling arrays. The hot path is completely unchanged -- only
a single stack-limit comparison is added per call.1 parent 00c0a9b commit 6399068
3 files changed
Lines changed: 69 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1820 | 1820 | | |
1821 | 1821 | | |
1822 | 1822 | | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
1823 | 1828 | | |
1824 | 1829 | | |
1825 | 1830 | | |
| |||
1839 | 1844 | | |
1840 | 1845 | | |
1841 | 1846 | | |
| 1847 | + | |
1842 | 1848 | | |
1843 | | - | |
| 1849 | + | |
1844 | 1850 | | |
1845 | | - | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
1846 | 1868 | | |
1847 | 1869 | | |
1848 | 1870 | | |
| |||
1877 | 1899 | | |
1878 | 1900 | | |
1879 | 1901 | | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
1880 | 1907 | | |
1881 | 1908 | | |
1882 | 1909 | | |
| |||
0 commit comments