Skip to content

Commit b8077e4

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix memory leak in tidy_repair_file()
2 parents d3992b6 + c34def5 commit b8077e4

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ PHP NEWS
5050
. Fix 32-bit wordwrap test failures. (orlitzky)
5151
. Fixed bug GH-14774 (time_sleep_until overflow). (David Carlier)
5252

53+
- Tidy:
54+
. Fix memory leak in tidy_repair_file(). (nielsdos)
55+
5356
- Treewide:
5457
. Fix compatibility with libxml2 2.13.2. (nielsdos)
5558

ext/tidy/tests/parsing_file_too_large.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ try {
4747
} catch (\Throwable $e) {
4848
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
4949
}
50+
51+
try {
52+
tidy_repair_file($path);
53+
} catch (\Throwable $e) {
54+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
55+
}
5056
?>
5157
--CLEAN--
5258
<?php
@@ -58,3 +64,4 @@ int(0)
5864
ValueError: Input string is too long
5965
ValueError: Input string is too long
6066
ValueError: Input string is too long
67+
ValueError: tidy_repair_file(): Argument #1 ($filename) Input string is too long

ext/tidy/tidy.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
304304
}
305305

306306
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
307-
zend_argument_value_error(1, "is too long");
307+
if (is_file) {
308+
zend_string_release_ex(data, false);
309+
zend_argument_value_error(1, "Input string is too long");
310+
} else {
311+
zend_argument_value_error(1, "is too long");
312+
}
308313
RETURN_THROWS();
309314
}
310315

0 commit comments

Comments
 (0)