Skip to content

Forked PHPTs for using multi-byte paths #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ext/bz2/tests/003-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
bzread() tests
--SKIPIF--
<?php if (!extension_loaded("bz2")) print "skip"; ?>
--FILE--
<?php

$fd = bzopen(dirname(__FILE__)."/003私はガラスを食べられます.txt.bz2","r");
var_dump(bzread());
var_dump(bzread($fd, 1 ,0));
var_dump(bzread($fd, 0));
var_dump(bzread($fd, -10));
var_dump(bzread($fd, 1));
var_dump(bzread($fd, 2));
var_dump(bzread($fd, 100000));

echo "Done\n";
?>
--EXPECTF--
Warning: bzread() expects at least 1 parameter, 0 given in %s on line %d
bool(false)

Warning: bzread() expects at most 2 parameters, 3 given in %s on line %d
bool(false)
string(0) ""

Warning: bzread(): length may not be negative in %s on line %d
bool(false)
string(1) "R"
string(2) "is"
string(251) "ing up from the heart of the desert
Rising up for Jerusalem
Rising up from the heat of the desert
Building up Old Jerusalem
Rising up from the heart of the desert
Rising up for Jerusalem
Rising up from the heat of the desert
Heading out for Jerusalem
"
Done
Binary file not shown.
42 changes: 42 additions & 0 deletions ext/exif/tests/bug34704-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Bug #34704 (Infinite recursion due to corrupt JPEG)
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--INI--
output_handler=
zlib.output_compression=0
--FILE--
<?php
$infile = dirname(__FILE__).'/bug34704私はガラスを食べられます.jpg';
var_dump(exif_read_data($infile));
?>
===DONE===
--EXPECTF--
array(7) {
["FileName"]=>
string(12) "bug34704.jpg"
["FileDateTime"]=>
int(%d)
["FileSize"]=>
int(9976)
["FileType"]=>
int(2)
["MimeType"]=>
string(10) "image/jpeg"
["SectionsFound"]=>
string(4) "IFD0"
["COMPUTED"]=>
array(5) {
["html"]=>
string(24) "width="386" height="488""
["Height"]=>
int(488)
["Width"]=>
int(386)
["IsColor"]=>
int(1)
["ByteOrderMotorola"]=>
int(0)
}
}
===DONE===
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions ext/exif/tests/bug68113-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Bug #68113 (Heap corruption in exif_thumbnail())
--SKIPIF--
<?php
extension_loaded("exif") or die("skip need exif");
?>
--FILE--
<?php
var_dump(exif_thumbnail(__DIR__."/bug68113私はガラスを食べられます.jpg"));
?>
Done
--EXPECTF--
Warning: exif_thumbnail(bug68113.jpg): File structure corrupted in %s%ebug68113.php on line 2

Warning: exif_thumbnail(bug68113.jpg): Invalid JPEG file in %s%ebug68113.php on line 2
bool(false)
Done
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ext/exif/tests/exif_imagetype_basic-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Check for exif_imagetype default behaviour
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--INI--
output_handler=
zlib.output_compression=0
--FILE--
<?php

/* Prototype : int exif_imagetype ( string $filename )
* Description: Determine the type of an image
* Source code: ext/exif/exif.c
*/
echo "*** Testing exif_imagetype() : basic functionality ***\n";

var_dump(exif_imagetype(dirname(__FILE__).'/test2私はガラスを食べられます.jpg'));
?>
===Done===
--EXPECT--
*** Testing exif_imagetype() : basic functionality ***
int(2)
===Done===
62 changes: 62 additions & 0 deletions ext/exif/tests/exif_read_exif_data_basic-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Check for read_exif_data default behaviour
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--INI--
output_handler=
zlib.output_compression=0
--FILE--
<?php

/* Prototype : array read_exif_data ( string $filename [, string $sections [, bool $arrays [, bool $thumbnail ]]] )
* Description: Alias of exif_read_data()
* Source code: ext/exif/exif.c
*/
echo "*** Testing read_exif_data() : basic functionality ***\n";

print_r(read_exif_data(dirname(__FILE__).'/test2私はガラスを食べられます.jpg'));
?>
===Done===
--EXPECTF--
*** Testing read_exif_data() : basic functionality ***
Array
(
[FileName] => test2.jpg
[FileDateTime] => %d
[FileSize] => 1240
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, COMMENT
[COMPUTED] => Array
(
[html] => width="1" height="1"
[Height] => 1
[Width] => 1
[IsColor] => 1
[ByteOrderMotorola] => 1
[UserComment] => Exif test image.
[UserCommentEncoding] => ASCII
[Copyright] => Photo (c) M.Boerger, Edited by M.Boerger.
[Copyright.Photographer] => Photo (c) M.Boerger
[Copyright.Editor] => Edited by M.Boerger.
[Thumbnail.FileType] => 2
[Thumbnail.MimeType] => image/jpeg
)

[Copyright] => Photo (c) M.Boerger
[UserComment] => ASCII
[THUMBNAIL] => Array
(
[JPEGInterchangeFormat] => 134
[JPEGInterchangeFormatLength] => 523
)

[COMMENT] => Array
(
[0] => Comment #1.
[1] => Comment #2.
[2] => Comment #3end
)

)
===Done===
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
73 changes: 73 additions & 0 deletions ext/fileinfo/tests/bug61964-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Bug #61964 (finfo_open with directory cause invalid free)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

$magic_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic私はガラスを食べられます';

$ret = @finfo_open(FILEINFO_NONE, $magic_file . ".non-exits私はガラスを食べられます");
var_dump($ret);

$dir = __DIR__ . "/test-folder";
@mkdir($dir);

$magic_file_copy = $dir . "/magic私はガラスを食べられます.copy";
$magic_file_copy2 = $magic_file_copy . "2";
copy($magic_file, $magic_file_copy);
copy($magic_file, $magic_file_copy2);

$ret = finfo_open(FILEINFO_NONE, $dir);
var_dump($ret);

$ret = @finfo_open(FILEINFO_NONE, $dir);
var_dump($ret);

$ret = @finfo_open(FILEINFO_NONE, $dir. "/non-exits-dir私はガラスを食べられます");
var_dump($ret);

// write some test files to test folder
file_put_contents($dir . "/test1.txt", "string\n> Core\n> Me");
file_put_contents($dir . "/test2.txt", "a\nb\n");
@mkdir($dir . "/test-inner-folder私はガラスを食べられます");

finfo_open(FILEINFO_NONE, $dir);
echo "DONE: testing dir with files\n";

rmdir($dir . "/test-inner-folder私はガラスを食べられます");
unlink($dir . "/test1.txt");
unlink($dir . "/test2.txt");

unlink($magic_file_copy);
unlink($magic_file_copy2);
rmdir($dir);
?>
===DONE===
--EXPECTF--
bool(false)
resource(%d) of type (file_info)
resource(%d) of type (file_info)
bool(false)

Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: type `Core' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: offset ` Me' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: type `Me' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: offset `a' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: type `a' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: offset `b' invalid in %sbug61964.php on line %d

Notice: finfo_open(): Warning: type `b' invalid in %sbug61964.php on line %d

Warning: finfo_open(): Failed to load magic database at '%stest-folder'. in %sbug61964.php on line %d
DONE: testing dir with files
===DONE===
17 changes: 17 additions & 0 deletions ext/fileinfo/tests/bug67647-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Bug #67647: Bundled libmagic 5.17 does not detect quicktime files correctly
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

$f = dirname(__FILE__) . DIRECTORY_SEPARATOR . "67647私はガラスを食べられます.mov";

$fi = new finfo(FILEINFO_MIME_TYPE);
var_dump($fi->file($f));
?>
+++DONE+++
--EXPECT--
string(15) "video/quicktime"
+++DONE+++

19 changes: 19 additions & 0 deletions ext/fileinfo/tests/bug71527-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug #71527 Buffer over-write in finfo_open with malformed magic file
--SKIPIF--
<?php
if (!class_exists('finfo'))
die('skip no fileinfo extension');
--ENV--
USE_ZEND_ALLOC=0
--FILE--
<?php
$finfo = finfo_open(FILEINFO_NONE, dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug71527私はガラスを食べられます.magic");
$info = finfo_file($finfo, __FILE__);
var_dump($info);
?>
--EXPECTF--
Warning: finfo_open(): Failed to load magic database at '%sbug71527.magic'. in %sbug71527.php on line %d

Warning: finfo_file() expects parameter 1 to be resource, boolean given in %sbug71527.php on line %d
bool(false)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
39 changes: 39 additions & 0 deletions ext/fileinfo/tests/cve-2014-1943-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Bug #66731: file: infinite recursion
--SKIPIF--
<?php
if (!class_exists('finfo'))
die('skip no fileinfo extension');
--FILE--
<?php
$fd = __DIR__.'/cve-2014-1943私はガラスを食べられます.data';
$fm = __DIR__.'/cve-2014-1943私はガラスを食べられます.magic';

$a = "\105\122\000\000\000\000\000";
$b = str_repeat("\001", 250000);
$m = "0 byte x\n".
">(1.b) indirect x\n";

file_put_contents($fd, $a);
$fi = finfo_open(FILEINFO_NONE);
var_dump(finfo_file($fi, $fd));
finfo_close($fi);

file_put_contents($fd, $b);
file_put_contents($fm, $m);
$fi = finfo_open(FILEINFO_NONE, $fm);
var_dump(finfo_file($fi, $fd));
finfo_close($fi);
?>
Done
--CLEAN--
<?php
@unlink(__DIR__.'/cve-2014-1943.data');
@unlink(__DIR__.'/cve-2014-1943.magic');
?>
--EXPECTF--
string(%d) "%s"

Warning: finfo_file(): Failed identify data 0:indirect recursion nesting (%d) exceeded in %s on line %d
bool(false)
Done

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 byte x
>(1.b) indirect x
35 changes: 35 additions & 0 deletions ext/fileinfo/tests/cve-2014-3538-mb.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Bug #66731: file: extensive backtraking
--SKIPIF--
<?php
if (!class_exists('finfo'))
die('skip no fileinfo extension');
--FILE--
<?php
$fd = __DIR__.'/cve-2014-3538私はガラスを食べられます.data';

file_put_contents($fd,
'try:' .
str_repeat("\n", 1000000));

$fi = finfo_open(FILEINFO_NONE);
$t = microtime(true);
var_dump(finfo_file($fi, $fd));
$t = microtime(true) - $t;
finfo_close($fi);
if ($t < 1) {
echo "Ok\n";
} else {
printf("Failed, time=%.2f\n", $t);
}

?>
Done
--CLEAN--
<?php
@unlink(__DIR__.'/cve-2014-3538.data');
?>
--EXPECTF--
string(%d) "%s"
Ok
Done
Loading