Simplify WBMP imagecreatefromstring() detection #16782
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to the WBMP specification[1], the first field (type) of a WBMP is a multi-byte integer, but only type
0
is supported. Thus there is no need to read a multi-byte integer. The second field (fix header) is a single byte; reading a multi-byte integer is not really wrong, since the fix header field is laid out in a way which allows it to be treated as such, but the check whether the MBI is greater than or equal to zero is pretty useless, because negative values could only be returned if overflow occurs (MBIs are unsigned).So the only useful assumption we can make is that the first byte is zero; we let
gdImageCreateFromWBMPCtx()
figure out the rest.[1] https://www.wapforum.org/what/technical/SPEC-WAESpec-19990524.pdf section 6
At first I wanted to use src.wbmp for the test but it failed due to
php-src/ext/gd/gd.c
Lines 1386 to 1389 in b948332
src.wbmp is only 9 bytes. We could fix this, but I don't think it's worth it, because such small WBMPs likely don't exist in practice (and even larger WBMPs likely are no longer relevant).