Repository navigation
Add Info::checked_raw_bytes - #739
Open
aaronjmars wants to merge 1 commit into
Open
aaronjmars wants to merge 1 commit into
aaronjmars wants to merge 1 commit into
Conversation
Info::raw_bytes multiplies height by the row length without a check, so very large dimensions overflow (a panic in debug builds, a wrapped value in release). Add a checked variant built on checked_raw_row_length that returns None when the size does not fit in a usize, and point to it from the raw_bytes docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Info::raw_bytescomputesheight * raw_row_length()with plain arithmetic, so for very large dimensions it overflows: a panic in debug builds and a wrapped, too-small value in release builds.This adds
Info::checked_raw_bytes, built on the existingchecked_raw_row_length, which returnsNonewhen the size does not fit in ausize.raw_byteskeeps its current behavior; its docs now point to the checked variant for dimensions from untrusted input.Includes a unit test for a normal size and for
u32::MAX x u32::MAXRGBA16, plus a CHANGES.md entry.