1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 23:18:13 +02:00
Files
archived-php-src/ext/phar/tests/bug70091.phpt
T
Christoph M. Becker 6a0b889f57 Fix #70091: Phar does not mark UTF-8 filenames in ZIP archives
The default encoding of filenames in a ZIP archive is IBM Code Page
437.  Phar, however, only supports UTF-8 filenames.  Therefore we have
to mark filenames as being stored in UTF-8 by setting the general
purpose bit 11 (the language encoding flag).

The effect of not setting this bit for non ASCII filenames can be seen
in popular tools like 7-Zip and UnZip, but not when extracting the
archives via ext/phar (which is agnostic to the filename encoding), or
via ext/zip (which guesses the encoding).  Thus we add a somewhat
brittle low-level test case.

Closes GH-6630.
2021-01-26 19:14:25 +01:00

61 lines
1.1 KiB
PHP

--TEST--
Bug #70091 (Phar does not mark UTF-8 filenames in ZIP archives)
--SKIPIF--
<?php
if (!extension_loaded('phar')) die('skip phar extension not available');
if (!extension_loaded('zlib')) die('skip zlib extension not available');
?>
--FILE--
<?php
$phar = new PharData(__DIR__ . '/bug70091.zip');
$phar->addFromString('föö', '');
$phar->addFromString('foo', '');
unset($phar);
$stream = fopen(__DIR__ . '/bug70091.zip', 'r');
$data = fread($stream, 8);
var_dump(unpack('H8sig/@6/nflags', $data));
fseek($stream, 53);
$data = fread($stream, 8);
var_dump(unpack('H8sig/@6/nflags', $data));
fseek($stream, 104);
$data = fread($stream, 10);
var_dump(unpack('H8sig/@8/nflags', $data));
fseek($stream, 173);
$data = fread($stream, 10);
var_dump(unpack('H8sig/@8/nflags', $data));
?>
--EXPECT--
array(2) {
["sig"]=>
string(8) "504b0304"
["flags"]=>
int(8)
}
array(2) {
["sig"]=>
string(8) "504b0304"
["flags"]=>
int(8)
}
array(2) {
["sig"]=>
string(8) "504b0102"
["flags"]=>
int(8)
}
array(2) {
["sig"]=>
string(8) "504b0102"
["flags"]=>
int(8)
}
--CLEAN--
<?php
@unlink(__DIR__ . '/bug70091.zip');
?>