Skip to content

Commit 2aeefb1

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phar crash and file corruption with SplFileObject
2 parents 50a5a6f + 405be1c commit 2aeefb1

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ PHP NEWS
4444

4545
- Phar:
4646
. Fix stream double free in phar. (nielsdos, dixyes)
47+
. Fix phar crash and file corruption with SplFileObject. (nielsdos)
4748

4849
- SOAP:
4950
. Fixed bug GH-18990, bug #81029, bug #47314 (SOAP HTTP socket not closing

ext/phar/phar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
27002700
/* remove this from the new phar */
27012701
continue;
27022702
}
2703-
if (!entry->is_modified && entry->fp_refcount) {
2703+
if (entry->fp_refcount) {
27042704
/* open file pointers refer to this fp, do not free the stream */
27052705
switch (entry->fp_type) {
27062706
case PHAR_FP:

ext/phar/stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,12 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou
449449
{
450450
phar_entry_data *data = (phar_entry_data *) stream->abstract;
451451

452-
php_stream_seek(data->fp, data->position, SEEK_SET);
452+
php_stream_seek(data->fp, data->position + data->zero, SEEK_SET);
453453
if (count != php_stream_write(data->fp, buf, count)) {
454454
php_stream_wrapper_log_error(stream->wrapper, stream->flags, "phar error: Could not write %d characters to \"%s\" in phar \"%s\"", (int) count, data->internal_file->filename, data->phar->fname);
455455
return -1;
456456
}
457-
data->position = php_stream_tell(data->fp);
457+
data->position = php_stream_tell(data->fp) - data->zero;
458458
if (data->position > (zend_off_t)data->internal_file->uncompressed_filesize) {
459459
data->internal_file->uncompressed_filesize = data->position;
460460
}

ext/phar/tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ static int phar_tar_writeheaders_int(phar_entry_info *entry, void *argument) /*
834834
php_stream_write(fp->new, padding, ((entry->uncompressed_filesize +511)&~511) - entry->uncompressed_filesize);
835835
}
836836

837-
if (!entry->is_modified && entry->fp_refcount) {
837+
if (entry->fp_refcount) {
838838
/* open file pointers refer to this fp, do not free the stream */
839839
switch (entry->fp_type) {
840840
case PHAR_FP:

ext/phar/tests/gh19038.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-19038 (Phar crash and data corruption with SplFileObject)
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--FILE--
8+
<?php
9+
10+
$phar = new Phar(__DIR__ . "/gh19038.phar");
11+
$phar->addFromString("file", "123");
12+
$file = $phar["file"]->openFile();
13+
$file->fseek(3);
14+
var_dump($file->fwrite("456", 3));
15+
$file->fseek(0);
16+
echo $file->fread(100);
17+
18+
?>
19+
--CLEAN--
20+
<?php
21+
@unlink(__DIR__ . "/gh19038.phar");
22+
?>
23+
--EXPECT--
24+
int(3)
25+
123456

0 commit comments

Comments
 (0)