[php-src] master: Merge branch 'PHP-8.6'
| From: | Weilin Du | Date: | Sun, 01 Nov 2026 06:34:32 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143111@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-11-01T14:30:45+08:00
Commit: https://github.com/php/php-src/commit/b0199f749d76dcd5362e562eb70ac0cfc71d3842
Raw diff: https://github.com/php/php-src/commit/b0199f749d76dcd5362e562eb70ac0cfc71d3842.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix GH-25089: Heap buffer over-read via crafted alias size in zip-based phar (#25099)
Changed paths:
A ext/phar/tests/zip/gh25089.phpt
M ext/phar/zip.c
Diff:
diff --git a/ext/phar/tests/zip/gh25089.phpt b/ext/phar/tests/zip/gh25089.phpt
new file mode 100644
index 000000000000..ec68c035f0c4
--- /dev/null
+++ b/ext/phar/tests/zip/gh25089.phpt
@@ -0,0 +1,35 @@
+--TEST--
+GH-25089 (Heap buffer over-read via crafted alias size in zip-based phar)
+--EXTENSIONS--
+phar
+zlib
+--FILE--
+<?php
+$name = '.phar/alias.txt';
+$alias = 'ABCD';
+$data = gzdeflate($alias);
+$crc = crc32($alias);
+$claimed = 0x1000;
+
+$local = "PK\x03\x04"
+ . pack('vvvvvVVVvv', 20, 0, 8, 0, 0,
+ $crc, strlen($data), $claimed, strlen($name), 0)
+ . $name . $data;
+$central = "PK\x01\x02"
+ . pack('vvvvvvVVVvvvvvVV', 20, 20, 0, 8, 0, 0,
+ $crc, strlen($data), $claimed, strlen($name), 0, 0, 0, 0, 0, 0)
+ . $name;
+$end = "PK\x05\x06"
+ . pack('vvvvVVv', 0, 0, 1, 1, strlen($central), strlen($local), 0);
+
+file_put_contents(__DIR__ . '/gh25089.zip', $local . $central . $end);
+
+$phar = new PharData(__DIR__ . '/gh25089.zip');
+var_dump($phar->getAlias());
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/gh25089.zip');
+?>
+--EXPECT--
+string(4) "ABCD"
diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index 8703979f234b..b1cfd897fa6c 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -645,7 +645,6 @@ zend_result phar_parse_zipfile(
zend_off_t restore_pos = php_stream_tell(fp);
php_stream_seek(fp, entry.offset, SEEK_SET);
- mydata->alias_len = entry.uncompressed_filesize;
if (entry.flags & PHAR_ENT_COMPRESSED_GZ) {
filter = php_stream_filter_create("zlib.inflate", NULL,
php_stream_is_persistent(fp));
@@ -732,6 +731,8 @@ zend_result phar_parse_zipfile(
}
}
+ mydata->alias_len = entry.uncompressed_filesize;
+
/* return to central directory parsing */
php_stream_seek(fp, restore_pos, SEEK_SET);
}