Skip to content

Renaming a file in a Phar to an already existing filename causes a NULL pointer dereference #13836

Closed
@YuanchengJiang

Description

@YuanchengJiang

Description

This case (https://github.com/php/php-src/blob/master/ext/phar/tests/bug47085.phpt) failed in the latest commit, not seen before.

--TEST--
Phar: PHP bug #47085: "rename() returns true even if the file in PHAR does not exist"
--EXTENSIONS--
phar
--INI--
phar.require_hash=0
phar.readonly=0
--FILE--
<?php
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';

$phar = new Phar($fname, 0, 'a.phar');
$phar['x'] = 'hi';
unset($phar);
rename("phar://a.phar/x", "phar://a.phar/y");
var_dump(rename("phar://a.phar/x", "phar://a.phar/y"));
?>
--CLEAN--
<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');?>
--EXPECTF--
Warning: rename(): phar error: cannot rename "phar://a.phar/x" to "phar://a.phar/y" from extracted phar archive, source does not exist in %sbug47085.php on line %d
bool(false)

Output:

/php-src/ext/phar/stream.c:864:10: runtime error: member access within null pointer of type 'phar_entry_info' (aka 'struct _phar_entry_info')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/phar/stream.c:864:10 in 

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions