-
Notifications
You must be signed in to change notification settings - Fork 7.9k
imageloadfont: Fix font loading in opposite endianness format #15231
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
base: master
Are you sure you want to change the base?
Conversation
This function used to (partially) be able to load fonts of the opposite endianness until php 7.4.0. This change restores this ability and also adds the missing part when the first character offset is non zero.
Thank you for the PR! However, I'm not sure if trying to cater to endianess makes sense. Or is anybody still using it? Are you using it? |
Yes, and I think it's a pretty handy fallback when freetype is not available, otherwise there is no easy way to print text on images. Also, it's fast, easy to use, very predictable and reproducible. I'd rather fix it properly. What would be the right way to do it regardless of the int size? |
On a second thought, it's not only the I think the parsing logic can be made independent by reading into a buffer made of uint32_t and then copying them to the GdFont struct after sanitizing it. If you think it makes sense, i'm happy to do that. |
And ugly, but that are a lot of GD drawing primitives anyway.
I think But the signedness might be an issue, too. For portable image fonts, we already assume two's complement implementation, which may not be granted. Then, flipping the bytes makes even more assumptions about the implementation. |
@cmb69 I gave it another shot.. do you think this would way it would be OK? Also is it really necessary to loop over php_stream_read() to accumulate the required data? I got rid of that piece of code but I can restore it if needed. |
I don't think we can just change the specification of the function; in this case that architectures with And thinking about deprecating Note that I'm not suggesting to deprecate the rest of the |
The ability to load fonts of the opposite endianness used to work until php 7.4.0 due to commit 88b6037. The same commit introduced a vulnerability due to a missing overflow check that was fixed later in commit d50532b, but the feature remains broken due to the early overflow check.
Furthermore, the initial implementation was missing the conversion (
FLIPWORD
macro) for the offset field, thus only fonts with zero offset (starting character) could be loaded correctly.Note that the missed conversion of the offset endianness is not exploitable as there is no way to craft a font that passes the overflow checks before and after the endianness swapping.
This patch fixes the functionality in a secure way, by guessing the endianness based on the number of characters (typically 256), and then performing the overflow check.