Skip to content

Add Info::checked_raw_bytes - #739

Open
aaronjmars wants to merge 1 commit into
image-rs:masterfrom
aaronjmars:checked-raw-bytes
Open

aaronjmars wants to merge 1 commit into
image-rs:masterfrom
aaronjmars:checked-raw-bytes

Conversation

@aaronjmars

Copy link
Copy Markdown

Info::raw_bytes computes height * 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 existing checked_raw_row_length, which returns None when the size does not fit in a usize. raw_bytes keeps 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::MAX RGBA16, plus a CHANGES.md entry.

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.
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