8000 Fix BMP header size by cmb69 · Pull Request #912 · libgd/libgd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix BMP header size #912

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix BMP header size #912

wants to merge 2 commits into from

Conversation

cmb69
Copy link
Member
@cmb69 cmb69 commented Dec 24, 2024

The bfSize member of BITMAPFILEHEADER is supposed to store the size of the BMP[1], and as such needs to be equal to the file size (for BMPs stored as files). Otherwise that may trip up readers; at least they may assume that the BMP is corrupted; e.g. ImageMagick warns about this.

While for compressed BMP images we actually calculate the size as we go, for uncompressed BMP images we calculate the size in advance, but so far did not account for padding of the rows.

We also fix the biSizeImage of the BITMAPINFOHEADER[2] accordingly.

[1] https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapfileheader
[2] https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader

@cmb69
Copy link
Member Author
cmb69 commented Dec 24, 2024

Ubuntu and macOS CI failures are unrelated.

cmb69 added a commit to cmb69/php-src that referenced this pull request Dec 24, 2024
@cmb69 cmb69 marked this pull request as draft December 25, 2024 11:45
@cmb69
Copy link
Member Author
cmb69 commented Dec 25, 2024

The CI failures are unrelated again (note that there are occassional segfaults on MinGW for different tests; that might justify some further investigation).

@cmb69 cmb69 marked this pull request as ready for review December 25, 2024 13:53
cmb69 added 2 commits January 2, 2025 00:20
The `bfSize` member of `BITMAPFILEHEADER` is supposed to store the size
of the BMP[1], and as such needs to be equal to the file size (for BMPs
stored as files).  Otherwise that may trip up readers; at least they
may assume that the BMP is corrupted; e.g. ImageMagick warns about
this.

While for compressed BMP images we actually calculate the size as we
go, for uncompressed BMP images we calculate the size in advance, but
so far did not account for padding of the rows.

We also fix the `biSizeImage` of the `BITMAPINFOHEADER`[2] accordingly.

[1] <https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapfileheader>
[2] <https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader>
We need to cater to compressed images, too.

We also augment the test case to check the `biSizeImage` field, and
also do the checks for compressed images.
@cmb69
Copy link
Member Author
cmb69 commented Jan 1, 2025

Rebased and force-pushed to get CI green (at least Ubuntu should be fixed in the meantime).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0