@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix HTTP body decompression in PHP 5.6

Summary:
Ref T10264. Under PHP 5.6, you are no longer allowed to use `compress.zlib://php://input` as an argument to either `fopen()` or `file_get_contents()`.

Instead, open `php://input` as a file handle, then add `zlib.inflate` as a stream wrapper. This requires some level of magic to work properly.

Test Plan:
First, I constructed a synthetic gzipped payload by typing some words into a file and using `gzcompress()` to compress it.

Then I used a `curl` command like this to make requests with it:

```
$ curl -X POST -H "Content-Length: 66" -H "Content-Type: text/plain" -H "Content-Encoding: gzip" --data-binary @payload.deflate -v http://127.0.0.1/
```

I modified Phabricator to just dump the raw request body and exit, and reproduced the issue under PHP 5.6 (no body, error in log) by brining up a micro instance in EC2 and installing php56 on it.

After this patch, it dumped the body properly instead, and PHP 5.5 also continued worked properly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10264

Differential Revision: https://secure.phabricator.com/D15314

+31 -4
+31 -4
support/PhabricatorStartup.php
··· 135 135 $encoding = null; 136 136 } 137 137 138 + $input_stream = fopen('php://input', 'rb'); 139 + if (!$input_stream) { 140 + self::didFatal( 141 + 'Unable to open "php://input" to read HTTP request body.'); 142 + } 143 + 138 144 if ($encoding === 'gzip') { 139 - $source_stream = 'compress.zlib://php://input'; 140 - } else { 141 - $source_stream = 'php://input'; 145 + $ok = stream_filter_append( 146 + $input_stream, 147 + 'zlib.inflate', 148 + STREAM_FILTER_READ, 149 + array( 150 + 'window' => 30, 151 + )); 152 + 153 + if (!$ok) { 154 + self::didFatal( 155 + 'Failed to append gzip inflate filter to HTTP request body input '. 156 + 'stream.'); 157 + } 158 + } 159 + 160 + $input_data = ''; 161 + while (!feof($input_stream)) { 162 + $read_bytes = fread($input_stream, 16 * 1024); 163 + if ($read_bytes === false) { 164 + self::didFatal( 165 + 'Failed to read input bytes from HTTP request body.'); 166 + } 167 + $input_data .= $read_bytes; 142 168 } 169 + fclose($input_stream); 143 170 144 - self::$rawInput = (string)file_get_contents($source_stream); 171 + self::$rawInput = $input_data; 145 172 } 146 173 147 174