1
0
mirror of https://github.com/php/php-src.git synced 2026-03-27 09:42:22 +01:00
Files
archived-php-src/sapi/fuzzer/generate_parser_corpus.php
Nikita Popov 40aa6b63d1 Further limit max input size in parser fuzzer
It's easy to cause stack overflows with degenerate cases like
"$$$$$x" repeated thousands of times. We have no interest in
addressing these.

Make the input size smaller to hopefully avoid these stack
overflows.
2021-09-23 13:11:21 +02:00

25 lines
716 B
PHP

<?php
$testsDir = __DIR__ . '/../../Zend/tests/';
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($testsDir),
RecursiveIteratorIterator::LEAVES_ONLY
);
$corpusDir = __DIR__ . '/corpus/parser';
@mkdir($corpusDir);
$maxLen = 7 * 1024;
foreach ($it as $file) {
if (!preg_match('/\.phpt$/', $file)) continue;
$code = file_get_contents($file);
if (!preg_match('/--FILE--\R(.*?)\R--([_A-Z]+)--/s', $code, $matches)) continue;
$code = $matches[1];
if (strlen($code) > $maxLen) continue;
$outFile = str_replace($testsDir, '', $file);
$outFile = str_replace('/', '_', $outFile);
$outFile = $corpusDir . '/' . $outFile;
file_put_contents($outFile, $code);
}