Skip to content

Fix memory leak in tidy_repair_file() #14862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/tidy/tests/parsing_file_too_large.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ try {
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
tidy_repair_file($path);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--CLEAN--
<?php
Expand All @@ -58,3 +64,4 @@ int(0)
ValueError: Input string is too long
ValueError: Input string is too long
ValueError: Input string is too long
ValueError: tidy_repair_file(): Argument #1 ($filename) Input string is too long
7 changes: 6 additions & 1 deletion ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
}

if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
zend_argument_value_error(1, "is too long");
if (is_file) {
zend_string_release_ex(data, false);
zend_argument_value_error(1, "Input string is too long");
} else {
zend_argument_value_error(1, "is too long");
}
RETURN_THROWS();
}

Expand Down
Loading