With a raised max_pixels on wasm32, a picture could pass every check and
then ask vec! for more than isize::MAX bytes for its scan line or its
float picture, which panics with a capacity overflow instead of returning
an error.
- decode checks the byte count of the scan line and of the float picture
against isize::MAX before allocating either, and returns
LimitExceeded("pixel count") when one is over.
- Each header line is measured as text after invalid bytes become U+FFFD,
and a line over isize::MAX bytes is LimitExceeded("header length").
- The resolution line reads its first four tokens without collecting the
rest.
- The size checks take the bound as a value, and tests check them against
the 32-bit bound without allocating.
With raised Limits, a gray image over 512 MiB could be converted to
color on wasm32, where the color plane needs more than isize::MAX bytes
and vec! panics with capacity overflow.
- Limits::check returns TooLarge when the byte count is over isize::MAX,
so the try_ forms report the size instead of OutOfMemory.
- map, to_color and to_kind clamp each side to 1..=MAX_SIDE when the
result would be over isize::MAX bytes, and map the top-left part.
- The size checks are pure functions that take the bound as a value, and
three tests check them against the 32-bit bound without allocating.
Adds crates/texture (craft-texture), the first step of RFC-0032
(storytold/craft-contrib#50). The code comes from MaterialCraft
crates/image/src/lib.rs at 31330629, with its six tests unchanged. No app
uses the crate yet.
Changes from the source:
- Image fields are private; from_data checks the size and the buffer
length, so a zero side can no longer reach a panic and a short buffer
is rejected instead of read with defaults.
- Limits caps the side, pixels and bytes; the try_ constructors and
try_map, try_to_kind, try_resize and try_to_rgba8_display reserve
memory first and return an error.
- Repeat sampling reduces the coordinate to its fractional part, so the
period holds at large coordinates.
- Bilinear sampling sums the four weighted texels and skips zero weights;
box shrinking sums in f64.
- generate_uv clamps the size before computing pixel centers.
- linear_to_srgb(NaN) returns NaN.
- rayon is behind the parallel feature.