Skip to content

Commit 15c351c

Browse files
committed
add NEWS entry; add simple test
1 parent 69aed1b commit 15c351c

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Improved IS_VAR operands fetching. (Laruence, Dmitry)
77
. Implemented internal operator overloading
88
(RFC: https://wiki.php.net/rfc/operator_overloading_gmp). (Nikita)
9+
. Enabled file uploads greater than 2G (Ralf Lang, Mike)
910

1011
- mysqlnd:
1112
. Disabled flag for SP OUT variables for 5.5+ servers as they are not natively

sapi/cli/tests/php_cli_server.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ define ("PHP_CLI_SERVER_HOSTNAME", "localhost");
33
define ("PHP_CLI_SERVER_PORT", 8964);
44
define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT);
55

6-
function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) {
6+
function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE, $cmd_args = null) {
77
$php_executable = getenv('TEST_PHP_EXECUTABLE');
88
$doc_root = __DIR__;
99
$router = "index.php";
@@ -19,14 +19,14 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE)
1919
);
2020

2121
if (substr(PHP_OS, 0, 3) == 'WIN') {
22-
$cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
22+
$cmd = "{$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
2323
if (!$no_router) {
2424
$cmd .= " {$router}";
2525
}
2626

2727
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
2828
} else {
29-
$cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
29+
$cmd = "exec {$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
3030
if (!$no_router) {
3131
$cmd .= " {$router}";
3232
}

sapi/cli/tests/upload_2G.phpt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--TEST--
2+
file upload greater than 2G
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
7+
if (PHP_INT_SIZE < 8) {
8+
die("skip need PHP_INT_SIZE>=8");
9+
}
10+
11+
if ($f = fopen("/proc/meminfo","r")) {
12+
while (!feof($f)) {
13+
if (!strncmp($line = fgets($f), "MemFree", 7)) {
14+
if (substr($line,8)/1024/1024 > 3) {
15+
$enough_free_ram = true;
16+
}
17+
}
18+
}
19+
}
20+
21+
if (empty($enough_free_ram)) {
22+
die("need +3G free RAM");
23+
}
24+
?>
25+
--FILE--
26+
<?php
27+
28+
echo "Test\n";
29+
30+
include "php_cli_server.inc";
31+
32+
php_cli_server_start("var_dump(\$_FILES);", false,
33+
"-d post_max_size=3G -d upload_max_filesize=3G");
34+
35+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
36+
$port = intval($port)?:80;
37+
$length = 2150000000;
38+
$output = "";
39+
40+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
41+
if (!$fp) {
42+
die("connect failed");
43+
}
44+
45+
$prev = "----123
46+
Content-Type: text/plain
47+
Content-Disposition: form-data; name=\"file1\"; filename=\"file1.txt\"\n\n";
48+
$post = "\n----123--\n";
49+
$total = $length + strlen($prev) + strlen($post);
50+
51+
fwrite($fp, <<<EOF
52+
POST /index.php HTTP/1.1
53+
Host: {$host}
54+
Content-Type: multipart/form-data; boundary=--123
55+
Content-Length: {$total}
56+
57+
{$prev}
58+
EOF
59+
) or die("write prev failed");
60+
61+
$data = str_repeat("0123456789", 10000);
62+
for ($i = 0; $i < $length; $i += 10000 * 10) {
63+
fwrite($fp, $data) or die("write failed @ ($i)");
64+
}
65+
66+
fwrite($fp, $post) or die("write post failed");
67+
68+
while (!feof($fp)) {
69+
$output .= fgets($fp);
70+
}
71+
echo $output;
72+
fclose($fp);
73+
?>
74+
Done
75+
--EXPECTF--
76+
Test
77+
78+
HTTP/1.1 200 OK
79+
Host: %s
80+
Connection: close
81+
X-Powered-By: PHP/%s
82+
Content-type: text/html
83+
84+
array(1) {
85+
["file1"]=>
86+
array(5) {
87+
["name"]=>
88+
string(9) "file1.txt"
89+
["type"]=>
90+
string(10) "text/plain"
91+
["tmp_name"]=>
92+
string(14) "/tmp/php%s"
93+
["error"]=>
94+
int(0)
95+
["size"]=>
96+
int(2150000000)
97+
}
98+
}
99+
Done

0 commit comments

Comments
 (0)