php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43187 Recursive loop crashes php instead of emitting error
Submitted: 2007-11-04 20:06 UTC Modified: 2007-11-06 20:27 UTC
From: thuejk at gmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
 [2007-11-04 20:06 UTC] thuejk at gmail dot com
Description:
------------
When running a recursive loop with lots of iterations, PHP will segfault.

This will usually be a problem when you write buggy code by accident, but I guess it is possible to imagine sane programs which uses lots of recursive calls.

In any case, it is somewhat hard to debug the crash when it happens, because you do not get an error message when running it in a browser.

Reproduce code:
---------------
<?php

$i=0;
function f() {
  global $i;
  printf("%d\n", $i++);
  f();
}

f();
?>


Expected result:
----------------
(Ignoring the fact that the posted function is tail recursive, and therefore could be rewritten as a non-recursive loop)

PHP should emit an E_ERROR before it runs out of space. Preferably also an E_RECOVERABLE_ERROR or E_WARNING a little before it really runs out of space.

Actual result:
--------------
$ php test.php
1
2
3
[...]
29066
29067
zsh: segmentation fault  php test.php


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-06 20:27 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is a known recursion limit.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 19:01:27 2024 UTC