diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 10e6a234edd9..4ea66f7b9f8b 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -425,7 +425,7 @@ static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */ } len2 = MIN(tmp_len - len1, ZSTR_LEN(entry->filename)); - memcpy(tmp + len1, entry->filename, len2); + memcpy(tmp + len1, ZSTR_VAL(entry->filename), len2); entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len); } diff --git a/ext/phar/tests/phar_set_inode_collision.phpt b/ext/phar/tests/phar_set_inode_collision.phpt new file mode 100644 index 000000000000..b3ec0ba471f9 --- /dev/null +++ b/ext/phar/tests/phar_set_inode_collision.phpt @@ -0,0 +1,53 @@ +--TEST-- +Phar: distinct same-length filenames in a phar archive should not collide on st_ino (phar_set_inode) +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +--FILE-- + 0, $a !== $b, $a !== $c, $b !== $c); +PHP; + +$spec = [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], +]; +$proc = proc_open([PHP_BINARY, '-n', '-r', $code, '--', $fname], $spec, $pipes); +fclose($pipes[0]); +$stdout = stream_get_contents($pipes[1]); +$stderr = stream_get_contents($pipes[2]); +fclose($pipes[1]); +fclose($pipes[2]); +$rc = proc_close($proc); + +var_dump($rc === 0, $stderr === ''); +echo $stdout; +?> +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true)