Skip to content

Commit 2b30b54

Browse files
committed
Merge remote-tracking branch 'phpsec/PHP-7.0.13' into PHP-7.0
* phpsec/PHP-7.0.13: Fixed bug #73418 Integer Overflow in "_php_imap_mail" leads to crash Fix #72696: imagefilltoborder stackoverflow on truecolor images Fix #72482: Ilegal write/read access caused by gdImageAALine overflow Fix bug #73144 and bug #73341 - remove extra dtor remove unreferenced var came in with merge Fix bug #73331 - do not try to serialize/unserialize objects wddx can not handle fix version set versions
2 parents 5faaf76 + de64358 commit 2b30b54

File tree

12 files changed

+133
-73
lines changed

12 files changed

+133
-73
lines changed

ext/gd/libgd/gd.c

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
11151115
}
11161116

11171117
/* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
1118-
if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im))) {
1118+
if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)-1) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im)-1)) {
11191119
return;
11201120
}
11211121

@@ -1299,55 +1299,10 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
12991299
long x, y, inc, frac;
13001300
long dx, dy,tmp;
13011301

1302-
if (y1 < 0 && y2 < 0) {
1303-
return;
1304-
}
1305-
if (y1 < 0) {
1306-
x1 += (y1 * (x1 - x2)) / (y2 - y1);
1307-
y1 = 0;
1308-
}
1309-
if (y2 < 0) {
1310-
x2 += (y2 * (x1 - x2)) / (y2 - y1);
1311-
y2 = 0;
1312-
}
1313-
1314-
/* bottom edge */
1315-
if (y1 >= im->sy && y2 >= im->sy) {
1316-
return;
1317-
}
1318-
if (y1 >= im->sy) {
1319-
x1 -= ((im->sy - y1) * (x1 - x2)) / (y2 - y1);
1320-
y1 = im->sy - 1;
1321-
}
1322-
if (y2 >= im->sy) {
1323-
x2 -= ((im->sy - y2) * (x1 - x2)) / (y2 - y1);
1324-
y2 = im->sy - 1;
1325-
}
1326-
1327-
/* left edge */
1328-
if (x1 < 0 && x2 < 0) {
1329-
return;
1330-
}
1331-
if (x1 < 0) {
1332-
y1 += (x1 * (y1 - y2)) / (x2 - x1);
1333-
x1 = 0;
1334-
}
1335-
if (x2 < 0) {
1336-
y2 += (x2 * (y1 - y2)) / (x2 - x1);
1337-
x2 = 0;
1338-
}
1339-
/* right edge */
1340-
if (x1 >= im->sx && x2 >= im->sx) {
1302+
/* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
1303+
if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)-1) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im)-1)) {
13411304
return;
13421305
}
1343-
if (x1 >= im->sx) {
1344-
y1 -= ((im->sx - x1) * (y1 - y2)) / (x2 - x1);
1345-
x1 = im->sx - 1;
1346-
}
1347-
if (x2 >= im->sx) {
1348-
y2 -= ((im->sx - x2) * (y1 - y2)) / (x2 - x1);
1349-
x2 = im->sx - 1;
1350-
}
13511306

13521307
dx = x2 - x1;
13531308
dy = y2 - y1;
@@ -1790,7 +1745,7 @@ void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
17901745
int leftLimit = -1, rightLimit;
17911746
int i, restoreAlphaBlending = 0;
17921747

1793-
if (border < 0) {
1748+
if (border < 0 || color < 0) {
17941749
/* Refuse to fill to a non-solid border */
17951750
return;
17961751
}

ext/gd/tests/bug72482.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #72482 (Ilegal write/read access caused by gdImageAALine overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$img = imagecreatetruecolor(13, 1007);
10+
imageantialias($img, true);
11+
imageline($img, 0, 0, 1073745919, 1073745919, 4096);
12+
13+
$img = imagecreatetruecolor(100, 100);
14+
imageantialias($img, true);
15+
imageline($img, 1094795585, 0, 2147483647, 255, 0xff);
16+
?>
17+
===DONE===
18+
--EXPECT--
19+
===DONE===

ext/gd/tests/bug72482_2.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug 72482 (Ilegal write/read access caused by gdImageAALine overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
10+
11+
$im = imagecreatetruecolor(10, 10);
12+
imagefilledrectangle($im, 0, 0, 9, 9, imagecolorallocate($im, 255, 255, 255));
13+
imageantialias($im, true);
14+
imageline($im, 0, 0, 10, 10, imagecolorallocate($im, 0, 0, 0));
15+
16+
test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug72482_2.png', $im);
17+
?>
18+
===DONE===
19+
--EXPECT--
20+
The images are equal.
21+
===DONE===

ext/gd/tests/bug72482_2.png

118 Bytes
Loading

ext/gd/tests/bug72696.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #72696 (imagefilltoborder stackoverflow on truecolor images)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$im = imagecreatetruecolor(10, 10);
10+
imagefilltoborder($im, 0, 0, 1, -2);
11+
?>
12+
===DONE===
13+
--EXPECT--
14+
===DONE===

ext/imap/php_imap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,7 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
39343934
char *tsm_errmsg = NULL;
39353935
ADDRESS *addr;
39363936
char *bufferTo = NULL, *bufferCc = NULL, *bufferBcc = NULL, *bufferHeader = NULL;
3937-
int offset, bufferLen = 0;
3937+
size_t offset, bufferLen = 0;
39383938
size_t bt_len;
39393939

39403940
if (headers) {

ext/pdo/pdo_stmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,7 @@ void pdo_stmt_init(void)
22992299
pdo_row_ce->ce_flags |= ZEND_ACC_FINAL; /* when removing this a lot of handlers need to be redone */
23002300
pdo_row_ce->create_object = pdo_row_new;
23012301
pdo_row_ce->serialize = pdo_row_serialize;
2302+
pdo_row_ce->unserialize = zend_class_unserialize_deny;
23022303
}
23032304

23042305
PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #73144 (Use-afte-free in ArrayObject Deserialization)
3+
--FILE--
4+
<?php
5+
try {
6+
$token = 'a:2:{i:0;O:1:"0":2:0s:1:"0";i:0;s:1:"0";a:1:{i:0;C:11:"ArrayObject":7:0x:i:0;r0';
7+
$obj = unserialize($token);
8+
} catch(Exception $e) {
9+
echo $e->getMessage()."\n";
10+
}
11+
12+
try {
13+
$inner = 'x:i:1;O:8:"stdClass":1:{};m:a:0:{}';
14+
$exploit = 'C:11:"ArrayObject":'.strlen($inner).':{'.$inner.'}';
15+
unserialize($exploit);
16+
} catch(Exception $e) {
17+
echo $e->getMessage()."\n";
18+
}
19+
?>
20+
--EXPECTF--
21+
Error at offset 6 of 7 bytes
22+
23+
Notice: ArrayObject::unserialize(): Unexpected end of serialized data in %sbug73341.php on line %d
24+
Error at offset 24 of 34 bytes

ext/wddx/tests/bug45901.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ echo wddx_serialize_value($xml, 'Variables') . "\n";
1414
echo "DONE";
1515
?>
1616
--EXPECTF--
17-
<wddxPacket version='1.0'><header><comment>Variables</comment></header><data><struct><var name='php_class_name'><string>SimpleXMLElement</string></var><var name='test'><struct><var name='php_class_name'><string>SimpleXMLElement</string></var></struct></var></struct></data></wddxPacket>
17+
18+
Warning: wddx_serialize_value(): Class SimpleXMLElement can not be serialized in %sbug45901.php on line %d
19+
<wddxPacket version='1.0'><header><comment>Variables</comment></header><data></data></wddxPacket>
1820
DONE

ext/wddx/tests/bug72790.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug 72790: wddx_deserialize null dereference with invalid xml
2+
Bug #72790: wddx_deserialize null dereference with invalid xml
33
--SKIPIF--
44
<?php
55
if (!extension_loaded('wddx')) {

ext/wddx/tests/bug73331.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #73331 (NULL Pointer Dereference in WDDX Packet Deserialization with PDORow)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("wddx") || !extension_loaded("pdo")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
$wddx = "<wddxPacket version='1.0'><header/><data><struct><var name='php_class_name'><string>PDORow</string></var></struct></data></wddxPacket>";
9+
var_dump(wddx_deserialize($wddx));
10+
?>
11+
--EXPECTF--
12+
13+
Warning: wddx_deserialize(): Class pdorow can not be unserialized in %s73331.php on line %d
14+
NULL
15+

ext/wddx/wddx.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
453453
zend_ulong idx;
454454
char tmp_buf[WDDX_BUF_LEN];
455455
HashTable *objhash, *sleephash;
456+
zend_class_entry *ce;
457+
PHP_CLASS_ATTRIBUTES;
458+
459+
PHP_SET_CLASS_ATTRIBUTES(obj);
460+
ce = Z_OBJCE_P(obj);
461+
if (!ce || ce->serialize || ce->unserialize) {
462+
php_error_docref(NULL, E_WARNING, "Class %s can not be serialized", ZSTR_VAL(class_name));
463+
PHP_CLEANUP_CLASS_ATTRIBUTES();
464+
return;
465+
}
456466

457467
ZVAL_STRING(&fname, "__sleep");
458468
/*
@@ -473,8 +483,6 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
473483
php_wddx_add_chunk_static(packet, WDDX_STRING_E);
474484
php_wddx_add_chunk_static(packet, WDDX_VAR_E);
475485

476-
PHP_CLEANUP_CLASS_ATTRIBUTES();
477-
478486
objhash = Z_OBJPROP_P(obj);
479487

480488
ZEND_HASH_FOREACH_VAL(sleephash, varname) {
@@ -491,10 +499,6 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
491499
php_wddx_add_chunk_static(packet, WDDX_STRUCT_E);
492500
}
493501
} else {
494-
PHP_CLASS_ATTRIBUTES;
495-
496-
PHP_SET_CLASS_ATTRIBUTES(obj);
497-
498502
php_wddx_add_chunk_static(packet, WDDX_STRUCT_S);
499503
snprintf(tmp_buf, WDDX_BUF_LEN, WDDX_VAR_S, PHP_CLASS_NAME_VAR);
500504
php_wddx_add_chunk(packet, tmp_buf);
@@ -503,8 +507,6 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
503507
php_wddx_add_chunk_static(packet, WDDX_STRING_E);
504508
php_wddx_add_chunk_static(packet, WDDX_VAR_E);
505509

506-
PHP_CLEANUP_CLASS_ATTRIBUTES();
507-
508510
objhash = Z_OBJPROP_P(obj);
509511
ZEND_HASH_FOREACH_KEY_VAL(objhash, idx, key, ent) {
510512
if (ent == obj) {
@@ -528,6 +530,8 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
528530
php_wddx_add_chunk_static(packet, WDDX_STRUCT_E);
529531
}
530532

533+
PHP_CLEANUP_CLASS_ATTRIBUTES();
534+
531535
zval_ptr_dtor(&fname);
532536
zval_ptr_dtor(&retval);
533537
}
@@ -947,23 +951,28 @@ static void php_wddx_pop_element(void *user_data, const XML_Char *name)
947951
pce = PHP_IC_ENTRY;
948952
}
949953

950-
/* Initialize target object */
951-
object_init_ex(&obj, pce);
954+
if (pce != PHP_IC_ENTRY && (pce->serialize || pce->unserialize)) {
955+
ZVAL_UNDEF(&ent2->data);
956+
php_error_docref(NULL, E_WARNING, "Class %s can not be unserialized", Z_STRVAL(ent1->data));
957+
} else {
958+
/* Initialize target object */
959+
object_init_ex(&obj, pce);
952960

953-
/* Merge current hashtable with object's default properties */
954-
zend_hash_merge(Z_OBJPROP(obj),
955-
Z_ARRVAL(ent2->data),
956-
zval_add_ref, 0);
961+
/* Merge current hashtable with object's default properties */
962+
zend_hash_merge(Z_OBJPROP(obj),
963+
Z_ARRVAL(ent2->data),
964+
zval_add_ref, 0);
957965

958-
if (incomplete_class) {
959-
php_store_class_name(&obj, Z_STRVAL(ent1->data), Z_STRLEN(ent1->data));
960-
}
966+
if (incomplete_class) {
967+
php_store_class_name(&obj, Z_STRVAL(ent1->data), Z_STRLEN(ent1->data));
968+
}
961969

962-
/* Clean up old array entry */
963-
zval_ptr_dtor(&ent2->data);
970+
/* Clean up old array entry */
971+
zval_ptr_dtor(&ent2->data);
964972

965-
/* Set stack entry to point to the newly created object */
966-
ZVAL_COPY_VALUE(&ent2->data, &obj);
973+
/* Set stack entry to point to the newly created object */
974+
ZVAL_COPY_VALUE(&ent2->data, &obj);
975+
}
967976

968977
/* Clean up class name var entry */
969978
zval_ptr_dtor(&ent1->data);

0 commit comments

Comments
 (0)