mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 00:47:56 +01:00
std: limit supported image dimensions to 0xFF_FFFF
This commit is contained in:
1 parent
d8c23a3a66
commit
e126c998e0
10 files changed
+175
-123
No files matched your search
@@ -6,6 +6,8 @@
|
|||||||
- Changed `lzw.set_literal_width` to `lzw.set_quirk`.
|
- Changed `lzw.set_literal_width` to `lzw.set_quirk`.
|
||||||
- Changed `set_quirk_enabled!(quirk: u32, enabled: bool)` to `set_quirk!(key:
|
- Changed `set_quirk_enabled!(quirk: u32, enabled: bool)` to `set_quirk!(key:
|
||||||
u32, value: u64) status`.
|
u32, value: u64) status`.
|
||||||
|
- Set image decoder pixel width and height inclusive maximum to `0xFF_FFFF`,
|
||||||
|
down from `0x7FFF_FFFF`.
|
||||||
|
|
||||||
The dot points below probably aren't of interest unless you're _writing_ Wuffs
|
The dot points below probably aren't of interest unless you're _writing_ Wuffs
|
||||||
code (instead of writing C/C++ code that _uses_ Wuffs' standard library).
|
code (instead of writing C/C++ code that _uses_ Wuffs' standard library).
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ but the `gif` could be replaced by `jpeg`, `png`, etc.
|
|||||||
Some image formats (GIF) are animated, consisting of an image header and then N
|
Some image formats (GIF) are animated, consisting of an image header and then N
|
||||||
frames. The image header gives e.g. the overall image's width and height. Each
|
frames. The image header gives e.g. the overall image's width and height. Each
|
||||||
frame consists of a frame header (e.g. frame rectangle bounds, display
|
frame consists of a frame header (e.g. frame rectangle bounds, display
|
||||||
duration) and a payload (the pixels).
|
duration) and a payload (the pixels). Headers are also known as configurations.
|
||||||
|
|
||||||
|
Wuffs image decoders will reject an image dimension (width or height) that is
|
||||||
|
above `0xFF_FFFF = 16_777215` pixels, even if the underlying image file format
|
||||||
|
permits more. This limit simplifies handling potential overflow. For example,
|
||||||
|
`width * bytes_per_pixel` will not overflow an `i32` and `width * height *
|
||||||
|
bytes_per_pixel` will not overflow an `i64`. Similarly, converting a pixel
|
||||||
|
width from integers to 26.6 fixed point units will not overflow an `i32`.
|
||||||
|
|
||||||
In general, there is one `wuffs_base__image_config` and then N pairs of
|
In general, there is one `wuffs_base__image_config` and then N pairs of
|
||||||
(`wuffs_base__frame_config`, frame). Non-animated (still) image formats are
|
(`wuffs_base__frame_config`, frame payload). Non-animated (still) image formats
|
||||||
treated the same way: that their N is 1 and their single frame's bounds equals
|
are treated the same way: that their N is 1 and their single frame's bounds
|
||||||
the overall image bounds.
|
equals the overall image bounds.
|
||||||
|
|
||||||
To decode everything (without knowing N in advance) sequentially:
|
To decode everything (without knowing N in advance) sequentially:
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
// ---------------- Images
|
// ---------------- Images
|
||||||
|
|
||||||
|
#define WUFFS_BASE__IMAGE__DIMENSION_MAX_INCL 0xFFFFFF
|
||||||
|
|
||||||
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
||||||
// Alpha, Red, Green, Blue color, as a uint32_t value. Its value is always
|
// Alpha, Red, Green, Blue color, as a uint32_t value. Its value is always
|
||||||
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
||||||
|
|||||||
@@ -270,6 +270,7 @@ var Statuses = [...]string{
|
|||||||
`"#no more information"`,
|
`"#no more information"`,
|
||||||
`"#not enough data"`,
|
`"#not enough data"`,
|
||||||
`"#out of bounds"`,
|
`"#out of bounds"`,
|
||||||
|
`"#unsupported image dimension"`,
|
||||||
`"#unsupported method"`,
|
`"#unsupported method"`,
|
||||||
`"#unsupported option"`,
|
`"#unsupported option"`,
|
||||||
`"#unsupported pixel swizzler option"`,
|
`"#unsupported pixel swizzler option"`,
|
||||||
@@ -612,7 +613,7 @@ var funcsOther = [...]string{
|
|||||||
|
|
||||||
// ---- image_config
|
// ---- image_config
|
||||||
|
|
||||||
"image_config.set!(pixfmt: u32, pixsub: u32, width: u32, height: u32," +
|
"image_config.set!(pixfmt: u32, pixsub: u32, width: u32[..= 0xFF_FFFF], height: u32[..= 0xFF_FFFF]," +
|
||||||
"first_frame_io_position: u64, first_frame_is_opaque: bool)",
|
"first_frame_io_position: u64, first_frame_is_opaque: bool)",
|
||||||
|
|
||||||
// ---- pixel_buffer
|
// ---- pixel_buffer
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ extern const char wuffs_base__error__interleaved_coroutine_calls[];
|
|||||||
extern const char wuffs_base__error__no_more_information[];
|
extern const char wuffs_base__error__no_more_information[];
|
||||||
extern const char wuffs_base__error__not_enough_data[];
|
extern const char wuffs_base__error__not_enough_data[];
|
||||||
extern const char wuffs_base__error__out_of_bounds[];
|
extern const char wuffs_base__error__out_of_bounds[];
|
||||||
|
extern const char wuffs_base__error__unsupported_image_dimension[];
|
||||||
extern const char wuffs_base__error__unsupported_method[];
|
extern const char wuffs_base__error__unsupported_method[];
|
||||||
extern const char wuffs_base__error__unsupported_option[];
|
extern const char wuffs_base__error__unsupported_option[];
|
||||||
extern const char wuffs_base__error__unsupported_pixel_swizzler_option[];
|
extern const char wuffs_base__error__unsupported_pixel_swizzler_option[];
|
||||||
@@ -3606,6 +3607,8 @@ wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) {
|
|||||||
|
|
||||||
// ---------------- Images
|
// ---------------- Images
|
||||||
|
|
||||||
|
#define WUFFS_BASE__IMAGE__DIMENSION_MAX_INCL 0xFFFFFF
|
||||||
|
|
||||||
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
||||||
// Alpha, Red, Green, Blue color, as a uint32_t value. Its value is always
|
// Alpha, Red, Green, Blue color, as a uint32_t value. Its value is always
|
||||||
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
||||||
@@ -10413,7 +10416,7 @@ struct wuffs_wbmp__decoder__struct {
|
|||||||
struct {
|
struct {
|
||||||
struct {
|
struct {
|
||||||
uint32_t v_i;
|
uint32_t v_i;
|
||||||
uint32_t v_x32;
|
uint32_t v_p;
|
||||||
} s_do_decode_image_config[1];
|
} s_do_decode_image_config[1];
|
||||||
struct {
|
struct {
|
||||||
uint64_t v_dst_bytes_per_pixel;
|
uint64_t v_dst_bytes_per_pixel;
|
||||||
@@ -12002,6 +12005,7 @@ const char wuffs_base__error__interleaved_coroutine_calls[] = "#base: interleave
|
|||||||
const char wuffs_base__error__no_more_information[] = "#base: no more information";
|
const char wuffs_base__error__no_more_information[] = "#base: no more information";
|
||||||
const char wuffs_base__error__not_enough_data[] = "#base: not enough data";
|
const char wuffs_base__error__not_enough_data[] = "#base: not enough data";
|
||||||
const char wuffs_base__error__out_of_bounds[] = "#base: out of bounds";
|
const char wuffs_base__error__out_of_bounds[] = "#base: out of bounds";
|
||||||
|
const char wuffs_base__error__unsupported_image_dimension[] = "#base: unsupported image dimension";
|
||||||
const char wuffs_base__error__unsupported_method[] = "#base: unsupported method";
|
const char wuffs_base__error__unsupported_method[] = "#base: unsupported method";
|
||||||
const char wuffs_base__error__unsupported_option[] = "#base: unsupported option";
|
const char wuffs_base__error__unsupported_option[] = "#base: unsupported option";
|
||||||
const char wuffs_base__error__unsupported_pixel_swizzler_option[] = "#base: unsupported pixel swizzler option";
|
const char wuffs_base__error__unsupported_pixel_swizzler_option[] = "#base: unsupported pixel swizzler option";
|
||||||
@@ -23072,9 +23076,12 @@ wuffs_bmp__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_width = t_7;
|
v_width = t_7;
|
||||||
}
|
}
|
||||||
if (v_width >= 2147483648) {
|
if (v_width > 2147483647) {
|
||||||
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
} else if (v_width > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_width = v_width;
|
self->private_impl.f_width = v_width;
|
||||||
{
|
{
|
||||||
@@ -23106,9 +23113,12 @@ wuffs_bmp__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_height = t_8;
|
v_height = t_8;
|
||||||
}
|
}
|
||||||
if (v_height >= 2147483648) {
|
if (v_height > 2147483647) {
|
||||||
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
} else if (v_height > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_height = v_height;
|
self->private_impl.f_height = v_height;
|
||||||
{
|
{
|
||||||
@@ -23203,9 +23213,12 @@ wuffs_bmp__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_width = t_11;
|
v_width = t_11;
|
||||||
}
|
}
|
||||||
if (v_width >= 2147483648) {
|
if (v_width > 2147483647) {
|
||||||
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
} else if (v_width > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_width = v_width;
|
self->private_impl.f_width = v_width;
|
||||||
{
|
{
|
||||||
@@ -23240,9 +23253,17 @@ wuffs_bmp__decoder__do_decode_image_config(
|
|||||||
if (v_height == 2147483648) {
|
if (v_height == 2147483648) {
|
||||||
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
} else if (v_height >= 2147483648) {
|
} else if (v_height > 2147483648) {
|
||||||
self->private_impl.f_height = (((uint32_t)(0 - v_height)) & 2147483647);
|
v_height = ((uint32_t)(0 - v_height));
|
||||||
|
if (v_height > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
self->private_impl.f_height = v_height;
|
||||||
self->private_impl.f_top_down = true;
|
self->private_impl.f_top_down = true;
|
||||||
|
} else if (v_height > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
} else {
|
} else {
|
||||||
self->private_impl.f_height = v_height;
|
self->private_impl.f_height = v_height;
|
||||||
}
|
}
|
||||||
@@ -24069,7 +24090,7 @@ wuffs_bmp__decoder__swizzle_none(
|
|||||||
|
|
||||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||||
uint32_t v_dst_bits_per_pixel = 0;
|
uint32_t v_dst_bits_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_pixel = 0;
|
uint32_t v_dst_bytes_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_row = 0;
|
uint64_t v_dst_bytes_per_row = 0;
|
||||||
uint32_t v_src_bytes_per_pixel = 0;
|
uint32_t v_src_bytes_per_pixel = 0;
|
||||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||||
@@ -24096,8 +24117,8 @@ wuffs_bmp__decoder__swizzle_none(
|
|||||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8);
|
||||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
|
||||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||||
label__outer__continue:;
|
label__outer__continue:;
|
||||||
@@ -24128,7 +24149,7 @@ wuffs_bmp__decoder__swizzle_none(
|
|||||||
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
||||||
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
||||||
}
|
}
|
||||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
|
||||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||||
if (self->private_impl.f_bits_per_pixel > 32) {
|
if (self->private_impl.f_bits_per_pixel > 32) {
|
||||||
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
||||||
@@ -24194,7 +24215,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
|||||||
|
|
||||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||||
uint32_t v_dst_bits_per_pixel = 0;
|
uint32_t v_dst_bits_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_pixel = 0;
|
uint32_t v_dst_bytes_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_row = 0;
|
uint64_t v_dst_bytes_per_row = 0;
|
||||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||||
wuffs_base__table_u8 v_tab = {0};
|
wuffs_base__table_u8 v_tab = {0};
|
||||||
@@ -24226,8 +24247,8 @@ wuffs_bmp__decoder__swizzle_rle(
|
|||||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8);
|
||||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
|
||||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||||
v_rle_state = self->private_impl.f_rle_state;
|
v_rle_state = self->private_impl.f_rle_state;
|
||||||
@@ -24239,7 +24260,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
|||||||
}
|
}
|
||||||
label__middle__continue:;
|
label__middle__continue:;
|
||||||
while (true) {
|
while (true) {
|
||||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
|
||||||
if (v_i <= ((uint64_t)(v_row.len))) {
|
if (v_i <= ((uint64_t)(v_row.len))) {
|
||||||
v_dst = wuffs_base__slice_u8__subslice_i(v_row, v_i);
|
v_dst = wuffs_base__slice_u8__subslice_i(v_row, v_i);
|
||||||
} else {
|
} else {
|
||||||
@@ -24456,7 +24477,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
|||||||
|
|
||||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||||
uint32_t v_dst_bits_per_pixel = 0;
|
uint32_t v_dst_bits_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_pixel = 0;
|
uint32_t v_dst_bytes_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_row = 0;
|
uint64_t v_dst_bytes_per_row = 0;
|
||||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||||
wuffs_base__table_u8 v_tab = {0};
|
wuffs_base__table_u8 v_tab = {0};
|
||||||
@@ -24488,8 +24509,8 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
|||||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8);
|
||||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
|
||||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||||
label__outer__continue:;
|
label__outer__continue:;
|
||||||
@@ -24558,7 +24579,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
|||||||
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
||||||
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
||||||
}
|
}
|
||||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
|
||||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||||
v_n = ((uint64_t)(v_p0));
|
v_n = ((uint64_t)(v_p0));
|
||||||
} else {
|
} else {
|
||||||
@@ -24596,7 +24617,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
|||||||
|
|
||||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||||
uint32_t v_dst_bits_per_pixel = 0;
|
uint32_t v_dst_bits_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_pixel = 0;
|
uint32_t v_dst_bytes_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_row = 0;
|
uint64_t v_dst_bytes_per_row = 0;
|
||||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||||
wuffs_base__table_u8 v_tab = {0};
|
wuffs_base__table_u8 v_tab = {0};
|
||||||
@@ -24625,8 +24646,8 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
|||||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8);
|
||||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
|
||||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||||
label__loop__continue:;
|
label__loop__continue:;
|
||||||
@@ -24642,7 +24663,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
|||||||
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
||||||
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
||||||
}
|
}
|
||||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
|
||||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||||
if (self->private_impl.f_bits_per_pixel == 1) {
|
if (self->private_impl.f_bits_per_pixel == 1) {
|
||||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
|
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
|
||||||
@@ -34266,7 +34287,7 @@ wuffs_gif__decoder__copy_to_image_buffer(
|
|||||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
}
|
}
|
||||||
v_bytes_per_pixel = (v_bits_per_pixel >> 3);
|
v_bytes_per_pixel = (v_bits_per_pixel >> 3);
|
||||||
v_width_in_bytes = (((uint64_t)(self->private_impl.f_width)) * ((uint64_t)(v_bytes_per_pixel)));
|
v_width_in_bytes = ((uint64_t)((self->private_impl.f_width * v_bytes_per_pixel)));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_pb, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_pb, 0);
|
||||||
label__0__continue:;
|
label__0__continue:;
|
||||||
while (v_src_ri < ((uint64_t)(a_src.len))) {
|
while (v_src_ri < ((uint64_t)(a_src.len))) {
|
||||||
@@ -37491,9 +37512,12 @@ wuffs_nie__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_a = t_2;
|
v_a = t_2;
|
||||||
}
|
}
|
||||||
if (v_a >= 2147483648) {
|
if (v_a > 2147483647) {
|
||||||
status = wuffs_base__make_status(wuffs_nie__error__bad_header);
|
status = wuffs_base__make_status(wuffs_nie__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
} else if (v_a > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_width = v_a;
|
self->private_impl.f_width = v_a;
|
||||||
{
|
{
|
||||||
@@ -37525,9 +37549,12 @@ wuffs_nie__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_a = t_3;
|
v_a = t_3;
|
||||||
}
|
}
|
||||||
if (v_a >= 2147483648) {
|
if (v_a > 2147483647) {
|
||||||
status = wuffs_base__make_status(wuffs_nie__error__bad_header);
|
status = wuffs_base__make_status(wuffs_nie__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
} else if (v_a > 16777215) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_height = v_a;
|
self->private_impl.f_height = v_a;
|
||||||
if (a_dst != NULL) {
|
if (a_dst != NULL) {
|
||||||
@@ -37877,7 +37904,7 @@ wuffs_nie__decoder__swizzle(
|
|||||||
|
|
||||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||||
uint32_t v_dst_bits_per_pixel = 0;
|
uint32_t v_dst_bits_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_pixel = 0;
|
uint32_t v_dst_bytes_per_pixel = 0;
|
||||||
uint64_t v_dst_bytes_per_row = 0;
|
uint64_t v_dst_bytes_per_row = 0;
|
||||||
uint32_t v_src_bytes_per_pixel = 0;
|
uint32_t v_src_bytes_per_pixel = 0;
|
||||||
wuffs_base__table_u8 v_tab = {0};
|
wuffs_base__table_u8 v_tab = {0};
|
||||||
@@ -37903,8 +37930,8 @@ wuffs_nie__decoder__swizzle(
|
|||||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8);
|
||||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
|
||||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||||
while (true) {
|
while (true) {
|
||||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||||
@@ -37918,7 +37945,7 @@ wuffs_nie__decoder__swizzle(
|
|||||||
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
|
||||||
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
|
||||||
}
|
}
|
||||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
|
||||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||||
v_src_bytes_per_pixel = 4;
|
v_src_bytes_per_pixel = 4;
|
||||||
if (self->private_impl.f_pixfmt == 2164308923) {
|
if (self->private_impl.f_pixfmt == 2164308923) {
|
||||||
@@ -41005,11 +41032,11 @@ wuffs_png__decoder__decode_ihdr(
|
|||||||
}
|
}
|
||||||
v_a32 = t_0;
|
v_a32 = t_0;
|
||||||
}
|
}
|
||||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
if ((v_a32 == 0) || (v_a32 > 2147483647)) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
} else if (v_a32 >= 16777216) {
|
} else if (v_a32 > 16777215) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_width = v_a32;
|
self->private_impl.f_width = v_a32;
|
||||||
@@ -41042,11 +41069,11 @@ wuffs_png__decoder__decode_ihdr(
|
|||||||
}
|
}
|
||||||
v_a32 = t_1;
|
v_a32 = t_1;
|
||||||
}
|
}
|
||||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
if ((v_a32 == 0) || (v_a32 > 2147483647)) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||||
goto exit;
|
goto exit;
|
||||||
} else if (v_a32 >= 16777216) {
|
} else if (v_a32 > 16777215) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
self->private_impl.f_height = v_a32;
|
self->private_impl.f_height = v_a32;
|
||||||
@@ -46721,8 +46748,7 @@ wuffs_wbmp__decoder__do_decode_image_config(
|
|||||||
|
|
||||||
uint8_t v_c = 0;
|
uint8_t v_c = 0;
|
||||||
uint32_t v_i = 0;
|
uint32_t v_i = 0;
|
||||||
uint32_t v_x32 = 0;
|
uint32_t v_p = 0;
|
||||||
uint64_t v_x64 = 0;
|
|
||||||
|
|
||||||
const uint8_t* iop_a_src = NULL;
|
const uint8_t* iop_a_src = NULL;
|
||||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
@@ -46738,7 +46764,7 @@ wuffs_wbmp__decoder__do_decode_image_config(
|
|||||||
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
|
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
|
||||||
if (coro_susp_point) {
|
if (coro_susp_point) {
|
||||||
v_i = self->private_data.s_do_decode_image_config[0].v_i;
|
v_i = self->private_data.s_do_decode_image_config[0].v_i;
|
||||||
v_x32 = self->private_data.s_do_decode_image_config[0].v_x32;
|
v_p = self->private_data.s_do_decode_image_config[0].v_p;
|
||||||
}
|
}
|
||||||
switch (coro_susp_point) {
|
switch (coro_susp_point) {
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
@@ -46766,7 +46792,7 @@ wuffs_wbmp__decoder__do_decode_image_config(
|
|||||||
}
|
}
|
||||||
v_i = 0;
|
v_i = 0;
|
||||||
while (v_i < 2) {
|
while (v_i < 2) {
|
||||||
v_x32 = 0;
|
v_p = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
{
|
{
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
@@ -46777,22 +46803,20 @@ wuffs_wbmp__decoder__do_decode_image_config(
|
|||||||
uint8_t t_1 = *iop_a_src++;
|
uint8_t t_1 = *iop_a_src++;
|
||||||
v_c = t_1;
|
v_c = t_1;
|
||||||
}
|
}
|
||||||
v_x32 |= ((uint32_t)((v_c & 127)));
|
v_p |= ((uint32_t)((v_c & 127)));
|
||||||
if ((v_c >> 7) == 0) {
|
if ((v_c >> 7) == 0) {
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
}
|
} else if (v_p > 131071) {
|
||||||
v_x64 = (((uint64_t)(v_x32)) << 7);
|
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
|
||||||
if (v_x64 > 4294967295) {
|
|
||||||
status = wuffs_base__make_status(wuffs_wbmp__error__bad_header);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_x32 = ((uint32_t)(v_x64));
|
v_p <<= 7;
|
||||||
}
|
}
|
||||||
label__0__break:;
|
label__0__break:;
|
||||||
if (v_i == 0) {
|
if (v_i == 0) {
|
||||||
self->private_impl.f_width = v_x32;
|
self->private_impl.f_width = v_p;
|
||||||
} else {
|
} else {
|
||||||
self->private_impl.f_height = v_x32;
|
self->private_impl.f_height = v_p;
|
||||||
}
|
}
|
||||||
v_i += 1;
|
v_i += 1;
|
||||||
}
|
}
|
||||||
@@ -46819,7 +46843,7 @@ wuffs_wbmp__decoder__do_decode_image_config(
|
|||||||
suspend:
|
suspend:
|
||||||
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||||
self->private_data.s_do_decode_image_config[0].v_i = v_i;
|
self->private_data.s_do_decode_image_config[0].v_i = v_i;
|
||||||
self->private_data.s_do_decode_image_config[0].v_x32 = v_x32;
|
self->private_data.s_do_decode_image_config[0].v_p = v_p;
|
||||||
|
|
||||||
goto exit;
|
goto exit;
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
+39
-25
@@ -31,8 +31,8 @@ pri const COMPRESSION_ALPHABITFIELDS : base.u32 = 6
|
|||||||
pri const COMPRESSION_LOW_BIT_DEPTH : base.u32 = 0x100
|
pri const COMPRESSION_LOW_BIT_DEPTH : base.u32 = 0x100
|
||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
width : base.u32[..= 0x7FFF_FFFF],
|
width : base.u32[..= 0xFF_FFFF],
|
||||||
height : base.u32[..= 0x7FFF_FFFF],
|
height : base.u32[..= 0xFF_FFFF],
|
||||||
|
|
||||||
// The call sequence state machine is discussed in
|
// The call sequence state machine is discussed in
|
||||||
// (/doc/std/image-decoders-call-sequence.md).
|
// (/doc/std/image-decoders-call-sequence.md).
|
||||||
@@ -131,6 +131,10 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
// Read the BITMAPINFOHEADER:
|
// Read the BITMAPINFOHEADER:
|
||||||
// - OS/2 is 12, 16 or 64 bytes.
|
// - OS/2 is 12, 16 or 64 bytes.
|
||||||
// - Windows is 40, 108 or 124 bytes.
|
// - Windows is 40, 108 or 124 bytes.
|
||||||
|
//
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
|
||||||
|
// says that width and height are LONG (signed i32) not DWORD (unsigned
|
||||||
|
// u32) and hence values above 0x7FFF_FFFF are invalid.
|
||||||
|
|
||||||
this.bitmap_info_len = args.src.read_u32le?()
|
this.bitmap_info_len = args.src.read_u32le?()
|
||||||
if this.padding < this.bitmap_info_len {
|
if this.padding < this.bitmap_info_len {
|
||||||
@@ -149,13 +153,17 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
|
|
||||||
} else if this.bitmap_info_len == 16 {
|
} else if this.bitmap_info_len == 16 {
|
||||||
width = args.src.read_u32le?()
|
width = args.src.read_u32le?()
|
||||||
if width >= 0x8000_0000 {
|
if width > 0x7FFF_FFFF {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
|
} else if width > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.width = width
|
this.width = width
|
||||||
height = args.src.read_u32le?()
|
height = args.src.read_u32le?()
|
||||||
if height >= 0x8000_0000 {
|
if height > 0x7FFF_FFFF {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
|
} else if height > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.height = height
|
this.height = height
|
||||||
planes = args.src.read_u16le_as_u32?()
|
planes = args.src.read_u16le_as_u32?()
|
||||||
@@ -166,19 +174,25 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
width = args.src.read_u32le?()
|
width = args.src.read_u32le?()
|
||||||
if width >= 0x8000_0000 {
|
if width > 0x7FFF_FFFF {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
|
} else if width > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.width = width
|
this.width = width
|
||||||
|
|
||||||
height = args.src.read_u32le?()
|
height = args.src.read_u32le?()
|
||||||
if height == 0x8000_0000 {
|
if height == 0x8000_0000 {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
} else if height >= 0x8000_0000 {
|
} else if height > 0x8000_0000 {
|
||||||
// The &0x7FFF_FFFF is redundant, but proves to the compiler that
|
height = 0 ~mod- height
|
||||||
// the result is within this.height's refined bounds.
|
if height > 0xFF_FFFF {
|
||||||
this.height = (0 ~mod- height) & 0x7FFF_FFFF
|
return base."#unsupported image dimension"
|
||||||
|
}
|
||||||
|
this.height = height
|
||||||
this.top_down = true
|
this.top_down = true
|
||||||
|
} else if height > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
} else {
|
} else {
|
||||||
this.height = height
|
this.height = height
|
||||||
}
|
}
|
||||||
@@ -503,7 +517,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||||
var dst_pixfmt : base.pixel_format
|
var dst_pixfmt : base.pixel_format
|
||||||
var dst_bits_per_pixel : base.u32[..= 256]
|
var dst_bits_per_pixel : base.u32[..= 256]
|
||||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||||
var dst_bytes_per_row : base.u64
|
var dst_bytes_per_row : base.u64
|
||||||
var src_bytes_per_pixel : base.u32[..= 4]
|
var src_bytes_per_pixel : base.u32[..= 4]
|
||||||
var dst_palette : slice base.u8
|
var dst_palette : slice base.u8
|
||||||
@@ -520,8 +534,8 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
|||||||
if (dst_bits_per_pixel & 7) <> 0 {
|
if (dst_bits_per_pixel & 7) <> 0 {
|
||||||
return base."#unsupported option"
|
return base."#unsupported option"
|
||||||
}
|
}
|
||||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||||
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
|
|
||||||
@@ -553,7 +567,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
|||||||
if dst_bytes_per_row < dst.length() {
|
if dst_bytes_per_row < dst.length() {
|
||||||
dst = dst[.. dst_bytes_per_row]
|
dst = dst[.. dst_bytes_per_row]
|
||||||
}
|
}
|
||||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||||
if i >= dst.length() {
|
if i >= dst.length() {
|
||||||
if this.bits_per_pixel > 32 {
|
if this.bits_per_pixel > 32 {
|
||||||
return "#unsupported BMP file"
|
return "#unsupported BMP file"
|
||||||
@@ -607,7 +621,7 @@ pri const RLE_STATE_DELTA_Y : base.u32 = 5
|
|||||||
pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||||
var dst_pixfmt : base.pixel_format
|
var dst_pixfmt : base.pixel_format
|
||||||
var dst_bits_per_pixel : base.u32[..= 256]
|
var dst_bits_per_pixel : base.u32[..= 256]
|
||||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||||
var dst_bytes_per_row : base.u64
|
var dst_bytes_per_row : base.u64
|
||||||
var dst_palette : slice base.u8
|
var dst_palette : slice base.u8
|
||||||
var tab : table base.u8
|
var tab : table base.u8
|
||||||
@@ -632,8 +646,8 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
|||||||
if (dst_bits_per_pixel & 7) <> 0 {
|
if (dst_bits_per_pixel & 7) <> 0 {
|
||||||
return base."#unsupported option"
|
return base."#unsupported option"
|
||||||
}
|
}
|
||||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||||
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
|
|
||||||
@@ -646,7 +660,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
|||||||
}
|
}
|
||||||
|
|
||||||
while.middle true {
|
while.middle true {
|
||||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||||
if i <= row.length() {
|
if i <= row.length() {
|
||||||
dst = row[i ..]
|
dst = row[i ..]
|
||||||
} else {
|
} else {
|
||||||
@@ -861,7 +875,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
|||||||
pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||||
var dst_pixfmt : base.pixel_format
|
var dst_pixfmt : base.pixel_format
|
||||||
var dst_bits_per_pixel : base.u32[..= 256]
|
var dst_bits_per_pixel : base.u32[..= 256]
|
||||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||||
var dst_bytes_per_row : base.u64
|
var dst_bytes_per_row : base.u64
|
||||||
var dst_palette : slice base.u8
|
var dst_palette : slice base.u8
|
||||||
var tab : table base.u8
|
var tab : table base.u8
|
||||||
@@ -885,8 +899,8 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
|||||||
if (dst_bits_per_pixel & 7) <> 0 {
|
if (dst_bits_per_pixel & 7) <> 0 {
|
||||||
return base."#unsupported option"
|
return base."#unsupported option"
|
||||||
}
|
}
|
||||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||||
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
|
|
||||||
@@ -968,7 +982,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
|||||||
if dst_bytes_per_row < dst.length() {
|
if dst_bytes_per_row < dst.length() {
|
||||||
dst = dst[.. dst_bytes_per_row]
|
dst = dst[.. dst_bytes_per_row]
|
||||||
}
|
}
|
||||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||||
if i >= dst.length() {
|
if i >= dst.length() {
|
||||||
n = p0 as base.u64
|
n = p0 as base.u64
|
||||||
} else {
|
} else {
|
||||||
@@ -990,7 +1004,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
|||||||
pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||||
var dst_pixfmt : base.pixel_format
|
var dst_pixfmt : base.pixel_format
|
||||||
var dst_bits_per_pixel : base.u32[..= 256]
|
var dst_bits_per_pixel : base.u32[..= 256]
|
||||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||||
var dst_bytes_per_row : base.u64
|
var dst_bytes_per_row : base.u64
|
||||||
var dst_palette : slice base.u8
|
var dst_palette : slice base.u8
|
||||||
var tab : table base.u8
|
var tab : table base.u8
|
||||||
@@ -1011,8 +1025,8 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
|||||||
if (dst_bits_per_pixel & 7) <> 0 {
|
if (dst_bits_per_pixel & 7) <> 0 {
|
||||||
return base."#unsupported option"
|
return base."#unsupported option"
|
||||||
}
|
}
|
||||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||||
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
dst_palette = args.dst.palette_or_else(fallback: this.scratch[1024 ..])
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
|
|
||||||
@@ -1029,7 +1043,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
|||||||
if dst_bytes_per_row < dst.length() {
|
if dst_bytes_per_row < dst.length() {
|
||||||
dst = dst[.. dst_bytes_per_row]
|
dst = dst[.. dst_bytes_per_row]
|
||||||
}
|
}
|
||||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||||
if i >= dst.length() {
|
if i >= dst.length() {
|
||||||
if this.bits_per_pixel == 1 {
|
if this.bits_per_pixel == 1 {
|
||||||
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
|
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
|
||||||
|
|||||||
@@ -13,8 +13,11 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
width : base.u32,
|
// These upper bounds should be 0xFFFF, on a strict reading of the GIF
|
||||||
height : base.u32,
|
// spec, but our looser implementation uses 0x1_FFFE. See
|
||||||
|
// test/data/artificial-gif/frame-out-of-bounds.gif.make-artificial.txt
|
||||||
|
width : base.u32[..= 0x1_FFFE],
|
||||||
|
height : base.u32[..= 0x1_FFFE],
|
||||||
|
|
||||||
// The call sequence state machine is discussed in
|
// The call sequence state machine is discussed in
|
||||||
// (/doc/std/image-decoders-call-sequence.md).
|
// (/doc/std/image-decoders-call-sequence.md).
|
||||||
@@ -60,10 +63,10 @@ pub struct decoder? implements base.image_decoder(
|
|||||||
num_decoded_frame_configs_value : base.u64,
|
num_decoded_frame_configs_value : base.u64,
|
||||||
num_decoded_frames_value : base.u64,
|
num_decoded_frames_value : base.u64,
|
||||||
|
|
||||||
frame_rect_x0 : base.u32,
|
frame_rect_x0 : base.u32[..= 0x0_FFFF],
|
||||||
frame_rect_y0 : base.u32,
|
frame_rect_y0 : base.u32[..= 0x0_FFFF],
|
||||||
frame_rect_x1 : base.u32,
|
frame_rect_x1 : base.u32[..= 0x1_FFFE],
|
||||||
frame_rect_y1 : base.u32,
|
frame_rect_y1 : base.u32[..= 0x1_FFFE],
|
||||||
|
|
||||||
// The dst_etc fields are the output cursor during copy_to_image_buffer.
|
// The dst_etc fields are the output cursor during copy_to_image_buffer.
|
||||||
dst_x : base.u32,
|
dst_x : base.u32,
|
||||||
@@ -788,9 +791,9 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
|
|||||||
this.frame_rect_x0 = args.src.read_u16le_as_u32?()
|
this.frame_rect_x0 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_y0 = args.src.read_u16le_as_u32?()
|
this.frame_rect_y0 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_x1 = args.src.read_u16le_as_u32?()
|
this.frame_rect_x1 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_x1 ~mod+= this.frame_rect_x0
|
this.frame_rect_x1 += this.frame_rect_x0
|
||||||
this.frame_rect_y1 = args.src.read_u16le_as_u32?()
|
this.frame_rect_y1 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_y1 ~mod+= this.frame_rect_y0
|
this.frame_rect_y1 += this.frame_rect_y0
|
||||||
|
|
||||||
this.dst_x = this.frame_rect_x0
|
this.dst_x = this.frame_rect_x0
|
||||||
this.dst_y = this.frame_rect_y0
|
this.dst_y = this.frame_rect_y0
|
||||||
@@ -1039,7 +1042,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
|
|||||||
}
|
}
|
||||||
bytes_per_pixel = bits_per_pixel >> 3
|
bytes_per_pixel = bits_per_pixel >> 3
|
||||||
|
|
||||||
width_in_bytes = (this.width as base.u64) * (bytes_per_pixel as base.u64)
|
width_in_bytes = (this.width * bytes_per_pixel) as base.u64
|
||||||
tab = args.pb.plane(p: 0)
|
tab = args.pb.plane(p: 0)
|
||||||
while src_ri < args.src.length() {
|
while src_ri < args.src.length() {
|
||||||
src = args.src[src_ri ..]
|
src = args.src[src_ri ..]
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
|||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
pixfmt : base.u32,
|
pixfmt : base.u32,
|
||||||
width : base.u32[..= 0x7FFF_FFFF],
|
width : base.u32[..= 0xFF_FFFF],
|
||||||
height : base.u32[..= 0x7FFF_FFFF],
|
height : base.u32[..= 0xFF_FFFF],
|
||||||
|
|
||||||
// The call sequence state machine is discussed in
|
// The call sequence state machine is discussed in
|
||||||
// (/doc/std/image-decoders-call-sequence.md).
|
// (/doc/std/image-decoders-call-sequence.md).
|
||||||
@@ -78,14 +78,18 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
}
|
}
|
||||||
|
|
||||||
a = args.src.read_u32le?()
|
a = args.src.read_u32le?()
|
||||||
if a >= 0x8000_0000 {
|
if a > 0x7FFF_FFFF {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
|
} else if a > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.width = a
|
this.width = a
|
||||||
|
|
||||||
a = args.src.read_u32le?()
|
a = args.src.read_u32le?()
|
||||||
if a >= 0x8000_0000 {
|
if a > 0x7FFF_FFFF {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
|
} else if a > 0xFF_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.height = a
|
this.height = a
|
||||||
|
|
||||||
@@ -200,7 +204,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||||
var dst_pixfmt : base.pixel_format
|
var dst_pixfmt : base.pixel_format
|
||||||
var dst_bits_per_pixel : base.u32[..= 256]
|
var dst_bits_per_pixel : base.u32[..= 256]
|
||||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||||
var dst_bytes_per_row : base.u64
|
var dst_bytes_per_row : base.u64
|
||||||
var src_bytes_per_pixel : base.u32[..= 8]
|
var src_bytes_per_pixel : base.u32[..= 8]
|
||||||
var tab : table base.u8
|
var tab : table base.u8
|
||||||
@@ -216,8 +220,8 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
|||||||
if (dst_bits_per_pixel & 7) <> 0 {
|
if (dst_bits_per_pixel & 7) <> 0 {
|
||||||
return base."#unsupported option"
|
return base."#unsupported option"
|
||||||
}
|
}
|
||||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
|
|
||||||
while true {
|
while true {
|
||||||
@@ -233,7 +237,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
|||||||
if dst_bytes_per_row < dst.length() {
|
if dst_bytes_per_row < dst.length() {
|
||||||
dst = dst[.. dst_bytes_per_row]
|
dst = dst[.. dst_bytes_per_row]
|
||||||
}
|
}
|
||||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||||
if i >= dst.length() {
|
if i >= dst.length() {
|
||||||
src_bytes_per_pixel = 4
|
src_bytes_per_pixel = 4
|
||||||
assert src_bytes_per_pixel > 0
|
assert src_bytes_per_pixel > 0
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ use "std/crc32"
|
|||||||
use "std/zlib"
|
use "std/zlib"
|
||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
|
|
||||||
// it means that (width * height * bytes_per_pixel) doesn't overflow a u64.
|
|
||||||
width : base.u32[..= 0x00FF_FFFF],
|
width : base.u32[..= 0x00FF_FFFF],
|
||||||
height : base.u32[..= 0x00FF_FFFF],
|
height : base.u32[..= 0x00FF_FFFF],
|
||||||
|
|
||||||
@@ -336,18 +334,18 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
|
|||||||
var a8 : base.u8
|
var a8 : base.u8
|
||||||
|
|
||||||
a32 = args.src.read_u32be?()
|
a32 = args.src.read_u32be?()
|
||||||
if (a32 == 0) or (a32 >= 0x8000_0000) {
|
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
} else if a32 >= 0x0100_0000 {
|
} else if a32 > 0xFF_FFFF {
|
||||||
return "#unsupported PNG file"
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.width = a32
|
this.width = a32
|
||||||
|
|
||||||
a32 = args.src.read_u32be?()
|
a32 = args.src.read_u32be?()
|
||||||
if (a32 == 0) or (a32 >= 0x8000_0000) {
|
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
|
||||||
return "#bad header"
|
return "#bad header"
|
||||||
} else if a32 >= 0x0100_0000 {
|
} else if a32 > 0xFF_FFFF {
|
||||||
return "#unsupported PNG file"
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
this.height = a32
|
this.height = a32
|
||||||
|
|
||||||
|
|||||||
+17
-20
@@ -18,8 +18,8 @@ pub status "#truncated input"
|
|||||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
width : base.u32,
|
width : base.u32[..= 0xFF_FFFF],
|
||||||
height : base.u32,
|
height : base.u32[..= 0xFF_FFFF],
|
||||||
|
|
||||||
// The call sequence state machine is discussed in
|
// The call sequence state machine is discussed in
|
||||||
// (/doc/std/image-decoders-call-sequence.md).
|
// (/doc/std/image-decoders-call-sequence.md).
|
||||||
@@ -48,10 +48,9 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
|||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||||
var c : base.u8
|
var c : base.u8
|
||||||
var i : base.u32
|
var i : base.u32
|
||||||
var x32 : base.u32
|
var p : base.u32[..= 0xFF_FFFF]
|
||||||
var x64 : base.u64
|
|
||||||
|
|
||||||
if this.call_sequence <> 0x00 {
|
if this.call_sequence <> 0x00 {
|
||||||
return base."#bad call sequence"
|
return base."#bad call sequence"
|
||||||
@@ -70,27 +69,25 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
|||||||
// Width, height.
|
// Width, height.
|
||||||
i = 0
|
i = 0
|
||||||
while i < 2 {
|
while i < 2 {
|
||||||
x32 = 0
|
p = 0
|
||||||
|
|
||||||
while true,
|
while true,
|
||||||
inv i < 2,
|
inv i < 2,
|
||||||
{
|
{
|
||||||
c = args.src.read_u8?()
|
c = args.src.read_u8?()
|
||||||
x32 |= (c & 0x7F) as base.u32
|
p |= (c & 0x7F) as base.u32
|
||||||
if (c >> 7) == 0 {
|
if (c >> 7) == 0 {
|
||||||
break
|
break
|
||||||
|
} else if p > 0x1_FFFF {
|
||||||
|
return base."#unsupported image dimension"
|
||||||
}
|
}
|
||||||
x64 = (x32 as base.u64) << 7
|
p <<= 7
|
||||||
if x64 > 0xFFFF_FFFF {
|
|
||||||
return "#bad header"
|
|
||||||
}
|
|
||||||
x32 = x64 as base.u32
|
|
||||||
} endwhile
|
} endwhile
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
this.width = x32
|
this.width = p
|
||||||
} else {
|
} else {
|
||||||
this.height = x32
|
this.height = p
|
||||||
}
|
}
|
||||||
i += 1
|
i += 1
|
||||||
} endwhile
|
} endwhile
|
||||||
@@ -212,19 +209,19 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
if this.width > 0 {
|
if this.width > 0 {
|
||||||
tab = args.dst.plane(p: 0)
|
tab = args.dst.plane(p: 0)
|
||||||
while dst_y < this.height {
|
while dst_y < this.height {
|
||||||
assert dst_y < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.height)
|
assert dst_y < 0xFF_FFFF via "a < b: a < c; c <= b"(c: this.height)
|
||||||
dst = tab.row_u32(y: dst_y)
|
dst = tab.row_u32(y: dst_y)
|
||||||
dst_x = 0
|
dst_x = 0
|
||||||
|
|
||||||
while dst_x < this.width,
|
while dst_x < this.width,
|
||||||
inv dst_y < 0xFFFF_FFFF,
|
inv dst_y < 0xFF_FFFF,
|
||||||
{
|
{
|
||||||
assert dst_x < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.width)
|
assert dst_x < 0xFF_FFFF via "a < b: a < c; c <= b"(c: this.width)
|
||||||
|
|
||||||
if (dst_x & 7) == 0 {
|
if (dst_x & 7) == 0 {
|
||||||
while args.src.length() <= 0,
|
while args.src.length() <= 0,
|
||||||
inv dst_x < 0xFFFF_FFFF,
|
inv dst_x < 0xFF_FFFF,
|
||||||
inv dst_y < 0xFFFF_FFFF,
|
inv dst_y < 0xFF_FFFF,
|
||||||
post args.src.length() > 0,
|
post args.src.length() > 0,
|
||||||
{
|
{
|
||||||
yield? base."$short read"
|
yield? base."$short read"
|
||||||
|
|||||||
Reference in new issue
Block a user