Skip to content

Commit ff6c9e2

Browse files
committed
Fixed bug #63377 (Segfault on output buffer)
1 parent 00d86af commit ff6c9e2

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
- Core:
1313
. Fixed bug #63451 (config.guess file does not have AIX 7 defined,
1414
shared objects are not created). (kemcline at au1 dot ibm dot com)
15+
. Fixed bug #63377 (Segfault on output buffer).
16+
(miau dot jp at gmail dot com, Laruence)
1517

1618
- Apache2 Handler SAPI:
1719
. Enabled Apache 2.4 configure option for Windows (Pierre, Anatoliy)

main/output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC)
607607
static inline void php_ob_append(const char *text, uint text_length TSRMLS_DC)
608608
{
609609
char *target;
610-
int original_ob_text_length;
610+
uint original_ob_text_length;
611611

612612
original_ob_text_length=OG(active_ob_buffer).text_length;
613613

tests/output/bug63377.phpt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
Bug #63377 (Segfault on output buffer > 2GB)
3+
--SKIPF--
4+
<?php
5+
$zend_mm_enabled = getenv("USE_ZEND_ALLOC");
6+
if ($zend_mm_enabled === "0") {
7+
die("skip Zend MM disabled");
8+
}
9+
10+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
11+
// check the available memory
12+
if (PHP_OS == 'Linux') {
13+
$lines = file('/proc/meminfo');
14+
$infos = array();
15+
foreach ($lines as $line) {
16+
$tmp = explode(":", $line);
17+
$index = strtolower($tmp[0]);
18+
$value = (int)ltrim($tmp[1], " ")*1024;
19+
$infos[$index] = $value;
20+
}
21+
$freeMemory = $infos['memfree']+$infos['buffers']+$infos['cached'];
22+
if ($freeMemory < 2100*1024*1024) {
23+
die('skip Not enough memory.');
24+
}
25+
}
26+
elseif (PHP_OS == 'FreeBSD') {
27+
$lines = explode("\n",`sysctl -a`);
28+
$infos = array();
29+
foreach ($lines as $line) {
30+
if(!$line){
31+
continue;
32+
}
33+
$tmp = explode(":", $line);
34+
$index = strtolower($tmp[0]);
35+
$value = trim($tmp[1], " ");
36+
$infos[$index] = $value;
37+
}
38+
$freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize'])
39+
+($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize'])
40+
+($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']);
41+
if ($freeMemory < 2100*1024*1024) {
42+
die('skip Not enough memory.');
43+
}
44+
}
45+
?>
46+
--FILE--
47+
<?php
48+
ini_set('memory_limit', '3072M');
49+
50+
ob_start();
51+
for ($i = 0; $i < 22; $i++) {
52+
echo str_repeat('a', 100 * 1024 * 1024);
53+
}
54+
ob_end_clean();
55+
echo "okey";
56+
?>
57+
--EXPECTF--
58+
okey

0 commit comments

Comments
 (0)