Skip to content

Commit

Permalink
Add support for various deflate compression levels
Browse files Browse the repository at this point in the history
Different compression levels yield a specific second byte in the magic
header for the deflate encoding. All of them can be decoded by the same
functions without any issues. Let them through, as they've been seen in
the wild.

Fixes WordPress#301
  • Loading branch information
soulseekah authored and jrfnl committed Sep 17, 2021
1 parent f93bf6b commit a2c8660
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,9 @@ public static function flatten($array) {
* @return string Decompressed string
*/
public static function decompress($data) {
if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") {
// All valid deflate, gzip header magic markers
$valid_magic = array("\x1f\x8b", "\x78\x01", "\x78\x5e", "\x78\x9c", "\x78\xda");
if (!in_array(substr($data, 0, 2), $valid_magic)) {
// Not actually compressed. Probably cURL ruining this for us.
return $data;
}
Expand Down

0 comments on commit a2c8660

Please sign in to comment.