Skip to content

BMP: Use NonZeroU16 to represent size internally#3046

Draft
RunDevelopment wants to merge 1 commit into
image-rs:mainfrom
RunDevelopment:bmp-nonzerou16-size
Draft

BMP: Use NonZeroU16 to represent size internally#3046
RunDevelopment wants to merge 1 commit into
image-rs:mainfrom
RunDevelopment:bmp-nonzerou16-size

Conversation

@RunDevelopment

Copy link
Copy Markdown
Member

The BMP decoder already (poorly) enforced a limit of 65535 and rejected empty images. This PR makes this behavior explicit by representing width and height using NonZeroU16. (I said "poorly" because ParsedInfoHeader::parse didn't enforce the limit correctly. See if you can spot the issue.)

This makes local reasoning for overflow and underflow a lot easier. Now it's trivial that height - 1 won't underflow. Similarly, many calculations can now be trivially proven to never overflow by looking at types.


This PR is a draft, because it doesn't handle ICO's height /= 2 correctly. I need #3042 for that.

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