Skip to content

Commit fa2125d

Browse files
committed
Merge branch 'PHP-5.6.30' into PHP-5.6
* PHP-5.6.30: Fix bug #73737 FPE when parsing a tag format Fix bug #73773 - Seg fault when loading hostile phar Fix bug #73825 - Heap out of bounds read on unserialize in finish_nested_data() Fix bug #73768 - Memory corruption when loading hostile phar Fix int overflows in phar (bug #73764)
2 parents a65ad95 + 1cda0d7 commit fa2125d

File tree

11 files changed

+646
-586
lines changed

11 files changed

+646
-586
lines changed

ext/exif/exif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ static size_t exif_convert_any_to_int(void *value, int format, int motorola_inte
13031303
if (s_den == 0) {
13041304
return 0;
13051305
} else {
1306-
return php_ifd_get32s(value, motorola_intel) / s_den;
1306+
return (size_t)((double)php_ifd_get32s(value, motorola_intel) / s_den);
13071307
}
13081308

13091309
case TAG_FMT_SSHORT: return php_ifd_get16u(value, motorola_intel);

ext/exif/tests/bug73737.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #73737 (Crash when parsing a tag format)
3+
--SKIPIF--
4+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
5+
--FILE--
6+
<?php
7+
$exif = exif_thumbnail(__DIR__ . '/bug73737.tiff');
8+
var_dump($exif);
9+
?>
10+
--EXPECTF--
11+
Warning: exif_thumbnail(bug73737.tiff): Error in TIFF: filesize(x0030) less than start of IFD dir(x10102) in %s line %d
12+
bool(false)

ext/exif/tests/bug73737.tiff

48 Bytes
Binary file not shown.

ext/phar/phar.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,14 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
981981
/* if the alias is stored we enforce it (implicit overrides explicit) */
982982
if (alias && alias_len && (alias_len != (int)tmp_len || strncmp(alias, buffer, tmp_len)))
983983
{
984-
buffer[tmp_len] = '\0';
985984
php_stream_close(fp);
986985

987986
if (signature) {
988987
efree(signature);
989988
}
990989

991990
if (error) {
992-
spprintf(error, 0, "cannot load phar \"%s\" with implicit alias \"%s\" under different alias \"%s\"", fname, buffer, alias);
991+
spprintf(error, 0, "cannot load phar \"%s\" with implicit alias \"%.*s\" under different alias \"%s\"", fname, tmp_len, buffer, alias);
993992
}
994993

995994
efree(savebuf);
@@ -1055,7 +1054,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
10551054
entry.is_persistent = mydata->is_persistent;
10561055

10571056
for (manifest_index = 0; manifest_index < manifest_count; ++manifest_index) {
1058-
if (buffer + 4 > endbuffer) {
1057+
if (buffer + 28 > endbuffer) {
10591058
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)")
10601059
}
10611060

@@ -1069,7 +1068,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
10691068
entry.manifest_pos = manifest_index;
10701069
}
10711070

1072-
if (entry.filename_len + 20 > endbuffer - buffer) {
1071+
if (entry.filename_len > endbuffer - buffer - 24) {
10731072
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)");
10741073
}
10751074

ext/phar/tests/bug73764.phar

138 Bytes
Binary file not shown.

ext/phar/tests/bug73764.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Phar: PHP bug #73764: Crash while loading hostile phar archive
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
chdir(__DIR__);
8+
try {
9+
$p = Phar::LoadPhar('bug73764.phar', 'alias.phar');
10+
echo "OK\n";
11+
} catch(PharException $e) {
12+
echo $e->getMessage();
13+
}
14+
?>
15+
--EXPECTF--
16+
internal corruption of phar "%sbug73764.phar" (truncated manifest entry)

ext/phar/tests/bug73768.phar

219 Bytes
Binary file not shown.

ext/phar/tests/bug73768.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Phar: PHP bug #73768: Memory corruption when loading hostile phar
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
chdir(__DIR__);
8+
try {
9+
$p = Phar::LoadPhar('bug73768.phar', 'alias.phar');
10+
echo "OK\n";
11+
} catch(PharException $e) {
12+
echo $e->getMessage();
13+
}
14+
?>
15+
--EXPECTF--
16+
cannot load phar "%sbug73768.phar" with implicit alias "" under different alias "alias.phar"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #73825 Heap out of bounds read on unserialize in finish_nested_data()
3+
--FILE--
4+
<?php
5+
$obj = unserialize('O:8:"00000000":');
6+
var_dump($obj);
7+
?>
8+
--EXPECTF--
9+
Warning: Bad unserialize data in %sbug73825.php on line %d
10+
11+
Notice: unserialize(): Error at offset 13 of 15 bytes in %sbug73825.php on line %d
12+
bool(false)

0 commit comments

Comments
 (0)