php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9321 eregi() crashes or runs terrible slow
Submitted: 2001-02-17 15:11 UTC Modified: 2001-02-22 10:44 UTC
From: mage at diablo dot hu Assigned:
Status: Closed Package: *Regular Expressions
PHP Version: 4.0.4pl1 OS: windows 98 / debian linux
Private report: No CVE-ID: None
 [2001-02-17 15:11 UTC] mage at diablo dot hu
I have an own e-mail source parser script for an archive engine. It has been working for a long time without errors, but it was crashed yesterday.
I have found the problem: eregi() halts with a 13k long text. This is same with PHP 4.0.3 Windows and PHP 4.0.4pl Debian Linux.

I include a short script to show it:

--------
<?php

  $cuts = array("_______________________________________________\n");

  $lines = file('\work\mail.txt');
  foreach ($lines as $l) {
    $text .= $l . "\n";
  }
  $text = str_replace(chr(13),'',$text);
  echo strlen($text) . "\n\n";

  foreach ($cuts as $c) {
    $ok = true;
    $cnt = 0;
    while ($ok && $cnt < 15) {
      echo $c . "\n";
      $regs[2] = '';
      eregi("(.*)($c)(.*)",$text,$regs);
      $text = $regs[1] . $regs[3];
      $ok = ($regs[2] == $c) && ($c != ''); // originally it was "$ok = $regs[2]", but I was trying to find the problem so I have changed
      $cnt++;
      echo strlen($text) . "\n\n";
    }
  }

?>

----------

This is the  result with windows/php4.0.3:
"
13238

_______________________________________________

13190

_______________________________________________

<br>
<b>Fatal error</b>:  Maximum execution time of 30 seconds exceeded in <b>C:\Webroot\test\eregi\test.php4</b> on line <b>19</b><br>
"
----
The result with PHP 4.0.4pl - Debian
"
13239

_______________________________________________

13191

_______________________________________________

13143

_______________________________________________

<br>
<b>Fatal error</b>:  Maximum execution time of 180 seconds exceeded in <b>/home/mage/public_html/test/test.php4</b> on line <b>18</b><br>
"
------

I think this is a bug, but that happend only with a specific text file. I should send it.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 10:44 UTC] stas@php.net
Regexps with two .* is doing _a real lot_ of backtracking
and is _VERY_ slow. In your example you can easily replace
it with strstr and a bit of string fiddling. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC