-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for various deflate compression levels #309
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs tests in the Encoding.php suite.
library/Requests.php
Outdated
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to use the $strict
parameter to in_array
, but otherwise looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in follow up commit. Tests included.
Codecov Report
@@ Coverage Diff @@
## master #309 +/- ##
============================================
+ Coverage 92.11% 92.11% +<.01%
+ Complexity 760 759 -1
============================================
Files 21 21
Lines 1762 1763 +1
============================================
+ Hits 1623 1624 +1
Misses 139 139
Continue to review full report at Codecov.
|
Added strict |
@schlessera I've just been looking at this PR. This seems like a good change. What do you think ? To get this ready to merge, IMO, the following actions are needed:
|
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
6815ae6
to
746b8f0
Compare
I've made the changes as per the above comment. This PR is now ready for review/merge. |
746b8f0
to
dea73d2
Compare
Strict check magic zlib magic markers. Add zlib compression level tests. ~~Enable encoding tests, these were not included in the test suite.~~
dea73d2
to
53f025b
Compare
... and document the source and what the marker is indicating. Includes switching to using `isset()` instead of `in_array()` for a tiny performance boost.
53f025b
to
c13e6bc
Compare
@@ -187,7 +187,7 @@ class Requests { | |||
/** | |||
* All (known) valid deflate, gzip header magic markers. | |||
* | |||
* These markers related to different compression levels. | |||
* These markers relate to different compression levels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
Thanks for the PR, @soulseekah ! |
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 #301