Skip to content

Commit

Permalink
Merge branch 'PHP-7.0' into PHP-7.1
Browse files Browse the repository at this point in the history
* PHP-7.0: (22 commits)
  Fix bug #72293 - Heap overflow in mysqlnd related to BIT fields
  I don't think 8cceb01 is needed
  Fix test
  Add check in fgetcsv in case sizeof(unit) != sizeof(size_t)
  Fix bug #73065: Out-Of-Bounds Read in php_wddx_push_element of wddx.c
  Fix bug #73035 (Out of bound when verify signature of tar phar in phar_parse_tarfile)
  Fix bug #73052 - Memory Corruption in During Deserialized-object Destruction
  Fix bug #73029 - Missing type check when unserializing SplArray
  Fix bug #72860: wddx_deserialize use-after-free
  Fix bug #73007: add locale length check
  Fix bug #72928 - Out of bound when verify signature of zip phar in phar_parse_zipfile
  sync NEWS
  Revert "Merge branch 'PHP-5.6' into PHP-7.0"
  Merge branch 'PHP-5.6' into PHP-7.0
  Merge branch 'PHP-5.6' into PHP-7.0
  Revert "Revert "Merge branch 'PHP-5.6' into PHP-7.0""
  fix version
  sync NEWS
  Fix bug #72957
  set versions
  ...
  • Loading branch information
smalyshev committed Sep 13, 2016
2 parents caea2c8 + 07c6bdb commit dad0e9d
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 31 deletions.
2 changes: 2 additions & 0 deletions ext/intl/msgformat/msgformat_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ PHP_FUNCTION( msgfmt_format_message )
RETURN_FALSE;
}

INTL_CHECK_LOCALE_LEN(slocale_len);

memset(mfo, 0, sizeof(*mfo));
msgformat_data_init(&mfo->mf_data);

Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias,
}
curloc = php_stream_tell(fp);
read = php_stream_read(fp, buf, size);
if (read != size) {
if (read != size || read <= 8) {
if (error) {
spprintf(error, 4096, "phar error: tar-based phar \"%s\" signature cannot be read", fname);
}
Expand Down
18 changes: 18 additions & 0 deletions ext/phar/tests/bug72928.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Phar: #72928 (Out of bound when verify signature of zip phar in phar_parse_zipfile)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--FILE--
<?php
chdir(__DIR__);
try {
$phar = new PharData('bug72928.zip');
var_dump($phar);
} catch(UnexpectedValueException $e) {
print $e->getMessage()."\n";
}
?>
DONE
--EXPECTF--
phar error: signature cannot be read in zip-based phar "%sbug72928.zip"
DONE
Binary file added ext/phar/tests/bug72928.zip
Binary file not shown.
18 changes: 18 additions & 0 deletions ext/phar/tests/bug73035.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Phar: #73035 (Out of bound when verify signature of tar phar in phar_parse_tarfile)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--FILE--
<?php
chdir(__DIR__);
try {
$phar = new PharData('bug73035.tar');
var_dump($phar);
} catch(UnexpectedValueException $e) {
print $e->getMessage()."\n";
}
?>
DONE
--EXPECTF--
phar error: tar-based phar "%sbug73035.tar" signature cannot be read
DONE
Binary file added ext/phar/tests/bug73035.tar
Binary file not shown.
28 changes: 28 additions & 0 deletions ext/phar/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,13 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type,
unsigned char digest[64];
PHP_SHA512_CTX context;

if (sig_len < sizeof(digest)) {
if (error) {
spprintf(error, 0, "broken signature");
}
return FAILURE;
}

PHP_SHA512Init(&context);
read_len = end_of_phar;

Expand Down Expand Up @@ -1636,6 +1643,13 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type,
unsigned char digest[32];
PHP_SHA256_CTX context;

if (sig_len < sizeof(digest)) {
if (error) {
spprintf(error, 0, "broken signature");
}
return FAILURE;
}

PHP_SHA256Init(&context);
read_len = end_of_phar;

Expand Down Expand Up @@ -1677,6 +1691,13 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type,
unsigned char digest[20];
PHP_SHA1_CTX context;

if (sig_len < sizeof(digest)) {
if (error) {
spprintf(error, 0, "broken signature");
}
return FAILURE;
}

PHP_SHA1Init(&context);
read_len = end_of_phar;

Expand Down Expand Up @@ -1710,6 +1731,13 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type,
unsigned char digest[16];
PHP_MD5_CTX context;

if (sig_len < sizeof(digest)) {
if (error) {
spprintf(error, 0, "broken signature");
}
return FAILURE;
}

PHP_MD5Init(&context);
read_len = end_of_phar;

Expand Down
2 changes: 1 addition & 1 deletion ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias,
php_stream_seek(fp, sizeof(phar_zip_file_header) + entry.header_offset + entry.filename_len + PHAR_GET_16(zipentry.extra_len), SEEK_SET);
sig = (char *) emalloc(entry.uncompressed_filesize);
read = php_stream_read(fp, sig, entry.uncompressed_filesize);
if (read != entry.uncompressed_filesize) {
if (read != entry.uncompressed_filesize || read <= 8) {
php_stream_close(sigfile);
efree(sig);
PHAR_ZIP_FAIL("signature cannot be read");
Expand Down
5 changes: 3 additions & 2 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *
zend_string *offset_key;
HashTable *ht = spl_array_get_hash_table(intern);

if (!offset || Z_ISUNDEF_P(offset)) {
if (!offset || Z_ISUNDEF_P(offset) || !ht) {
return &EG(uninitialized_zval);
}

Expand Down Expand Up @@ -1791,7 +1791,8 @@ SPL_METHOD(Array, unserialize)
intern->ar_flags |= flags & SPL_ARRAY_CLONE_MASK;
zval_ptr_dtor(&intern->array);
ZVAL_UNDEF(&intern->array);
if (!php_var_unserialize(&intern->array, &p, s + buf_len, &var_hash)) {
if (!php_var_unserialize(&intern->array, &p, s + buf_len, &var_hash)
|| (Z_TYPE(intern->array) != IS_ARRAY && Z_TYPE(intern->array) != IS_OBJECT)) {
goto outexcept;
}
var_push_dtor(&var_hash, &intern->array);
Expand Down
5 changes: 5 additions & 0 deletions ext/spl/tests/bug70068.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
Bug #70068 (Dangling pointer in the unserialization of ArrayObject items)
--FILE--
<?php
try {
$a = unserialize('a:3:{i:0;C:11:"ArrayObject":20:{x:i:0;r:3;;m:a:0:{};}i:1;d:11;i:2;S:31:"AAAAAAAABBBBCCCC\01\00\00\00\04\00\00\00\00\00\00\00\00\00\00";}');
} catch(Exception $e) {
print $e->getMessage()."\n";
}
?>
OK
--EXPECT--
Error at offset 10 of 20 bytes
OK
16 changes: 16 additions & 0 deletions ext/spl/tests/bug73029.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Bug #73029: Missing type check when unserializing SplArray
--FILE--
<?php
try {
$a = 'C:11:"ArrayObject":19:0x:i:0;r:2;;m:a:0:{}}';
$m = unserialize($a);
$x = $m[2];
} catch(UnexpectedValueException $e) {
print $e->getMessage() . "\n";
}
?>
DONE
--EXPECTF--
Error at offset 10 of 19 bytes
DONE
18 changes: 18 additions & 0 deletions ext/standard/tests/serialize/bug73052.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug #73052: Memory Corruption in During Deserialized-object Destruction
--FILE--
<?php

class obj {
var $ryat;
public function __destruct() {
$this->ryat = null;
}
}

$poc = 'O:3:"obj":1:{';
var_dump(unserialize($poc));
?>
--EXPECTF--
Notice: unserialize(): Error at offset 13 of 13 bytes in %sbug73052.php on line %d
bool(false)
17 changes: 0 additions & 17 deletions ext/standard/tests/strings/bug72703.phpt

This file was deleted.

27 changes: 27 additions & 0 deletions ext/wddx/tests/bug72860.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Bug #72860: wddx_deserialize use-after-free
--SKIPIF--
<?php
if (!extension_loaded('wddx')) {
die('skip. wddx not available');
}
?>
--FILE--
<?php

$xml=<<<XML
<?xml version='1.0'?>
<!DOCTYPE wddxPacket SYSTEM 'wddx_0100.dtd'>
<wddxPacket version='1.0'>
<recordset fieldNames='F'>
<field name='F'>
</recordset>
</wddxPacket>
XML;

var_dump(wddx_deserialize($xml));
?>
DONE
--EXPECT--
NULL
DONE
98 changes: 98 additions & 0 deletions ext/wddx/tests/bug73065.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
--TEST--
Bug #73065: Out-Of-Bounds Read in php_wddx_push_element of wddx.c
--SKIPIF--
<?php
if (!extension_loaded('wddx')) {
die('skip. wddx not available');
}
?>
--FILE--
<?php

$xml1 = <<<XML
<?xml version='1.0' ?>
<!DOCTYPE et SYSTEM 'w'>
<wddxPacket ven='1.0'>
<array>
<var Name="name">
<boolean value="keliu"></boolean>
</var>
<var name="1111">
<var name="2222">
<var name="3333"></var>
</var>
</var>
</array>
</wddxPacket>
XML;

$xml2 = <<<XML
<?xml version='1.0' ?>
<!DOCTYPE et SYSTEM 'w'>
<wddxPacket ven='1.0'>
<array>
<char Name="code">
<boolean value="keliu"></boolean>
</char>
</array>
</wddxPacket>
XML;

$xml3 = <<<XML
<?xml version='1.0' ?>
<!DOCTYPE et SYSTEM 'w'>
<wddxPacket ven='1.0'>
<array>
<boolean Name="value">
<boolean value="keliu"></boolean>
</boolean>
</array>
</wddxPacket>
XML;

$xml4 = <<<XML
<?xml version='1.0' ?>
<!DOCTYPE et SYSTEM 'w'>
<wddxPacket ven='1.0'>
<array>
<recordset Name="fieldNames">
<boolean value="keliu"></boolean>
</recordset>
</array>
</wddxPacket>
XML;

$xml5 = <<<XML
<?xml version='1.0' ?>
<!DOCTYPE et SYSTEM 'w'>
<wddxPacket ven='1.0'>
<array>
<field Name="name">
<boolean value="keliu"></boolean>
</field>
</array>
</wddxPacket>
XML;

for($i=1;$i<=5;$i++) {
$xmlvar = "xml$i";
$array = wddx_deserialize($$xmlvar);
var_dump($array);
}
?>
DONE
--EXPECTF--
array(0) {
}
array(0) {
}
array(0) {
}
array(1) {
[0]=>
array(0) {
}
}
array(0) {
}
DONE
Loading

0 comments on commit dad0e9d

Please sign in to comment.