Skip to content

Commit fa19a22

Browse files
committed
Merge branch 'PHP-5.6'
2 parents 1d609d2 + 9959ead commit fa19a22

File tree

12 files changed

+309
-34
lines changed

12 files changed

+309
-34
lines changed

ext/fileinfo/data_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121057,7 +121057,7 @@ const unsigned char php_magic_database[2803888] = {
121057121057
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121058121058
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121059121059
0x00, 0x00, 0x40, 0x00, 0x3D, 0x1B, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121060-
0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121060+
0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121061121061
0x5E, 0x5C, 0x73, 0x7B, 0x30, 0x2C, 0x31, 0x30, 0x30, 0x7D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x5C,
121062121062
0x73, 0x7B, 0x30, 0x2C, 0x31, 0x30, 0x30, 0x7D, 0x5B, 0x7B, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x00,
121063121063
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

ext/fileinfo/libmagic/softmagic.c

+18-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private int32_t mprint(struct magic_set *, struct magic *);
6767
private int32_t moffset(struct magic_set *, struct magic *);
6868
private void mdebug(uint32_t, const char *, size_t);
6969
private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
70-
const unsigned char *, uint32_t, size_t, size_t);
70+
const unsigned char *, uint32_t, size_t, struct magic *);
7171
private int mconvert(struct magic_set *, struct magic *, int);
7272
private int print_sep(struct magic_set *, int);
7373
private int handle_annotation(struct magic_set *, struct magic *);
@@ -1038,7 +1038,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
10381038

10391039
private int
10401040
mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1041-
const unsigned char *s, uint32_t offset, size_t nbytes, size_t linecnt)
1041+
const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m)
10421042
{
10431043
/*
10441044
* Note: FILE_SEARCH and FILE_REGEX do not actually copy
@@ -1058,15 +1058,24 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
10581058
const char *last; /* end of search region */
10591059
const char *buf; /* start of search region */
10601060
const char *end;
1061-
size_t lines;
1061+
size_t lines, linecnt, bytecnt;
10621062

1063+
linecnt = m->str_range;
1064+
bytecnt = linecnt * 80;
1065+
1066+
if (bytecnt == 0) {
1067+
bytecnt = 8192;
1068+
}
1069+
if (bytecnt > nbytes) {
1070+
bytecnt = nbytes;
1071+
}
10631072
if (s == NULL) {
10641073
ms->search.s_len = 0;
10651074
ms->search.s = NULL;
10661075
return 0;
10671076
}
10681077
buf = RCAST(const char *, s) + offset;
1069-
end = last = RCAST(const char *, s) + nbytes;
1078+
end = last = RCAST(const char *, s) + bytecnt;
10701079
/* mget() guarantees buf <= last */
10711080
for (lines = linecnt, b = buf; lines && b < end &&
10721081
((b = CAST(const char *,
@@ -1079,7 +1088,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
10791088
b++;
10801089
}
10811090
if (lines)
1082-
last = RCAST(const char *, s) + nbytes;
1091+
last = RCAST(const char *, s) + bytecnt;
10831092

10841093
ms->search.s = buf;
10851094
ms->search.s_len = last - buf;
@@ -1150,7 +1159,6 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
11501159
int *need_separator, int *returnval)
11511160
{
11521161
uint32_t soffset, offset = ms->offset;
1153-
uint32_t count = m->str_range;
11541162
int rv, oneed_separator, in_type;
11551163
char *sbuf, *rbuf;
11561164
union VALUETYPE *p = &ms->ms_value;
@@ -1162,13 +1170,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
11621170
}
11631171

11641172
if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
1165-
(uint32_t)nbytes, count) == -1)
1173+
(uint32_t)nbytes, m) == -1)
11661174
return -1;
11671175

11681176
if ((ms->flags & MAGIC_DEBUG) != 0) {
11691177
fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, "
1170-
"nbytes=%zu, count=%u)\n", m->type, m->flag, offset, o,
1171-
nbytes, count);
1178+
"nbytes=%zu)\n", m->type, m->flag, offset, o, nbytes);
11721179
mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
11731180
}
11741181

@@ -1661,7 +1668,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
16611668
if ((ms->flags & MAGIC_DEBUG) != 0)
16621669
fprintf(stderr, "indirect +offs=%u\n", offset);
16631670
}
1664-
if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1)
1671+
if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1)
16651672
return -1;
16661673
ms->offset = offset;
16671674

@@ -2093,7 +2100,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
20932100
zval *retval;
20942101
zval *subpats;
20952102
char *haystack;
2096-
2103+
20972104
MAKE_STD_ZVAL(retval);
20982105
ALLOC_INIT_ZVAL(subpats);
20992106

ext/fileinfo/magicdata.patch

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,58 @@
1-
Patches applied to file sources tree before generating magic.mgc
1+
Patches applied to file 5.17 sources tree before generating magic.mgc
22
and before running create_data_file.php to create data_file.c.
33

44

5+
6+
From 0b478f445b6b7540b58af5d1fe583fa9e48fd745 Mon Sep 17 00:00:00 2001
7+
From: Christos Zoulas <christos@zoulas.com>
8+
Date: Wed, 28 May 2014 19:52:36 +0000
9+
Subject: [PATCH] further optimize awk by not looking for the BEGIN regex until
10+
we found the BEGIN (Jan Kaluza)
11+
12+
---
13+
magic/Magdir/commands | 5 +++--
14+
1 file changed, 3 insertions(+), 2 deletions(-)
15+
16+
diff --git a/magic/Magdir/commands b/magic/Magdir/commands
17+
index bfffdef..26b2869 100644
18+
--- a/magic/Magdir/commands
19+
+++ b/magic/Magdir/commands
20+
@@ -49,7 +49,8 @@
21+
!:mime text/x-awk
22+
0 string/wt #!\ /usr/bin/awk awk script text executable
23+
!:mime text/x-awk
24+
-0 regex =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
25+
+0 search/16384 BEGIN
26+
+>0 regex =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
27+
28+
# AT&T Bell Labs' Plan 9 shell
29+
0 string/wt #!\ /bin/rc Plan 9 rc shell script text executable
30+
--
31+
2.0.3
32+
33+
From 71a8b6c0d758acb0f73e2e51421a711b5e9d6668 Mon Sep 17 00:00:00 2001
34+
From: Christos Zoulas <christos@zoulas.com>
35+
Date: Fri, 30 May 2014 16:48:44 +0000
36+
Subject: [PATCH] Limit regex search for BEGIN to the first 4K of the file.
37+
38+
---
39+
magic/Magdir/commands | 5 ++---
40+
1 file changed, 2 insertions(+), 3 deletions(-)
41+
42+
diff --git a/magic/Magdir/commands b/magic/Magdir/commands
43+
index 26b2869..bcd0f43 100644
44+
--- a/magic/Magdir/commands
45+
+++ b/magic/Magdir/commands
46+
@@ -49,8 +49,7 @@
47+
!:mime text/x-awk
48+
0 string/wt #!\ /usr/bin/awk awk script text executable
49+
!:mime text/x-awk
50+
-0 search/16384 BEGIN
51+
->0 regex =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
52+
+0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
53+
54+
# AT&T Bell Labs' Plan 9 shell
55+
0 string/wt #!\ /bin/rc Plan 9 rc shell script text executable
56+
--
57+
2.0.3
58+

ext/fileinfo/tests/cve-2014-3538.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #66731: file: extensive backtraking
3+
--SKIPIF--
4+
<?php
5+
if (!class_exists('finfo'))
6+
die('skip no fileinfo extension');
7+
--FILE--
8+
<?php
9+
$fd = __DIR__.'/cve-2014-3538.data';
10+
11+
file_put_contents($fd,
12+
'try:' .
13+
str_repeat("\n", 1000000));
14+
15+
$fi = finfo_open(FILEINFO_NONE);
16+
$t = microtime(true);
17+
var_dump(finfo_file($fi, $fd));
18+
$t = microtime(true) - $t;
19+
finfo_close($fi);
20+
if ($t < 1) {
21+
echo "Ok\n";
22+
} else {
23+
printf("Failed, time=%.2f\n", $t);
24+
}
25+
26+
?>
27+
Done
28+
--CLEAN--
29+
<?php
30+
@unlink(__DIR__.'/cve-2014-3538.data');
31+
?>
32+
--EXPECTF--
33+
string(%d) "%s"
34+
Ok
35+
Done

ext/gd/libgd/gdxpm.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ gdImagePtr gdImageCreateFromXpm (char *filename)
3131
if (ret != XpmSuccess) {
3232
return 0;
3333
}
34+
number = image.ncolors;
35+
for(i = 0; i < number; i++) {
36+
if (!image.colorTable[i].c_color) {
37+
goto done;
38+
}
39+
}
3440

3541
if (!(im = gdImageCreate(image.width, image.height))) {
3642
goto done;
3743
}
3844

39-
number = image.ncolors;
4045
colors = (int *) safe_emalloc(number, sizeof(int), 0);
4146
for (i = 0; i < number; i++) {
4247
switch (strlen (image.colorTable[i].c_color)) {
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
--TEST--
2+
Multiple result set with PS
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once("connect.inc");
7+
if (!$IS_MYSQLND) {
8+
die("skip mysqlnd only test");
9+
}
10+
require_once('skipifconnectfailure.inc');
11+
?>
12+
--FILE--
13+
<?php
14+
require_once("connect.inc");
15+
require('table.inc');
16+
17+
$stmt = mysqli_stmt_init($link);
18+
if (!$link->query('DROP PROCEDURE IF EXISTS p123')) {
19+
printf("[001] [%d] %s\n", $link->error, $link->errno);
20+
}
21+
22+
if (!$link->query("CREATE PROCEDURE p123() BEGIN SELECT id+12, CONCAT_WS('-',label,'ahoi') FROM test ORDER BY id LIMIT 1; SELECT id + 42, CONCAT_WS('---',label, label) FROM test ORDER BY id LIMIT 1; END")) {
23+
printf("[002] [%d] %s\n", $link->error, $link->errno);
24+
}
25+
26+
if (!($stmt = $link->prepare("CALL p123"))) {
27+
printf("[003] [%d] %s\n", $stmt->error, $stmt->errno);
28+
}
29+
30+
if (!$stmt->execute()) {
31+
printf("[005] [%d] %s\n", $stmt->error, $stmt->errno);
32+
}
33+
34+
$c_id = NULL;
35+
$c_label = NULL;
36+
if (!$stmt->bind_result($c_id, $c_label)) {
37+
printf("[004] [%d] %s\n", $stmt->error, $stmt->errno);
38+
}
39+
var_dump("pre:",$c_id, $c_label);
40+
41+
if (!$stmt->fetch()) {
42+
printf("[006] [%d] %s\n", $stmt->error, $stmt->errno);
43+
}
44+
45+
var_dump("post:",$c_id, $c_label);
46+
47+
if ($stmt->fetch()) {
48+
printf("[007] Shouldn't have fetched anything\n");
49+
var_dump($c_id, $c_label);
50+
}
51+
52+
if ($stmt->fetch()) {
53+
printf("[008] No more rows expected\n");
54+
}
55+
56+
if (!$stmt->more_results()) {
57+
printf("[009] Expected more results\n");
58+
} else {
59+
var_dump("[009] next_result:", $stmt->next_result());
60+
}
61+
62+
if (!$stmt->bind_result($c_id, $c_label)) {
63+
printf("[010] [%d] %s\n", $stmt->error, $stmt->errno);
64+
}
65+
var_dump("pre:",$c_id, $c_label);
66+
67+
if (!$stmt->fetch()) {
68+
printf("[011] [%d] %s\n", $stmt->error, $stmt->errno);
69+
}
70+
71+
var_dump("post:",$c_id, $c_label);
72+
73+
if ($stmt->fetch()) {
74+
printf("[012] No more rows expected\n");
75+
}
76+
77+
if (!$stmt->more_results()) {
78+
printf("[013] Expected more results\n");
79+
} else {
80+
var_dump("[013] next_result:", $stmt->next_result());
81+
}
82+
83+
if ($stmt->more_results()) {
84+
printf("[014] No more results expected\n");
85+
} else {
86+
printf("[014] No result, as expected\n");
87+
}
88+
89+
$stmt->close();
90+
$link->close();
91+
92+
93+
echo "done";
94+
?>
95+
--CLEAN--
96+
<?php
97+
require_once("connect.inc");
98+
if (!$link->query('DROP PROCEDURE IF EXISTS p123')) {
99+
printf("[001] [%d] %s\n", $link->error, $link->errno);
100+
}
101+
?>
102+
--EXPECTF--
103+
string(4) "pre:"
104+
NULL
105+
NULL
106+
string(5) "post:"
107+
int(13)
108+
string(6) "a-ahoi"
109+
string(18) "[009] next_result:"
110+
bool(true)
111+
string(4) "pre:"
112+
int(13)
113+
string(6) "a-ahoi"
114+
string(5) "post:"
115+
int(43)
116+
string(5) "a---a"
117+
string(18) "[013] next_result:"
118+
bool(true)
119+
[014] No result, as expected
120+
done

0 commit comments

Comments
 (0)