1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-19752: Phar decompression with invalid extension can cause UAF

The rename code can error out prior to the reassignment of the filename,
which is why the test causes a crash.
The rename code can also error out at a later point,
which means it will have already assigned the new filename.
We detect in which case we are in and act accordingly.

Closes GH-19761.
This commit is contained in:
Niels Dossche
2025-09-08 18:48:43 +02:00
parent ff84cb08ef
commit f6878b6ccf
3 changed files with 20 additions and 1 deletions

2
NEWS
View File

@@ -50,6 +50,8 @@ PHP NEWS
. Fix memory leak in phar tar temporary file error handling code. (nielsdos)
. Fix metadata leak when phar convert logic fails. (nielsdos)
. Fix memory leak on failure in phar_convert_to_other(). (nielsdos)
. Fixed bug GH-19752 (Phar decompression with invalid extension
can cause UAF). (nielsdos)
- Standard:
. Fixed bug GH-16649 (UAF during array_splice). (alexandre-daubois)

View File

@@ -2328,7 +2328,11 @@ no_copy:
if (phar->fp) {
php_stream_close(phar->fp);
}
efree(phar->fname);
if (phar->fname != source->fname) {
/* Depending on when phar_rename_archive() errors, the new filename
* may have already been assigned or it may still be the old one. */
efree(phar->fname);
}
efree(phar);
}
return NULL;

View File

@@ -0,0 +1,13 @@
--TEST--
GH-19752 (Phar decompression with invalid extension can cause UAF)
--FILE--
<?php
$phar = new PharData(__DIR__.'/gh19752.1');
try {
$phar->decompress("*");
} catch (BadMethodCallException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
data phar converted from "%sgh19752.1" has invalid extension *