From 24a2f12c30616e821810b442e721b95077ed8d74 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 4 May 2019 14:04:28 +1000 Subject: [PATCH] Add wuffs_gif__quirk_ignore_too_much_pixel_data --- release/c/wuffs-unsupported-snapshot.c | 3 ++- std/gif/decode_gif.wuffs | 3 ++- test/c/std/gif.c | 34 +++++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index ff537689..64c89b4d 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -10993,7 +10993,8 @@ wuffs_gif__decoder__copy_to_image_buffer(wuffs_gif__decoder* self, label_0_continue:; while (v_src_ri < ((uint64_t)(a_src.len))) { v_src = wuffs_base__slice_u8__subslice_i(a_src, v_src_ri); - if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) { + if ((self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && + !self->private_impl.f_quirk_enabled_ignore_too_much_pixel_data) { return wuffs_base__error__too_much_data; } v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y); diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index f7a08437..50686f40 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -977,7 +977,8 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base. while src_ri < args.src.length() { src = args.src[src_ri:] - if this.dst_y >= this.frame_rect_y1 { + if (this.dst_y >= this.frame_rect_y1) and + (not this.quirk_enabled_ignore_too_much_pixel_data) { return base."#too much data" } diff --git a/test/c/std/gif.c b/test/c/std/gif.c index fdb5a42a..52ff77a5 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -468,6 +468,7 @@ const char* do_test_wuffs_gif_decode(const char* filename, } const char* do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src, + uint32_t quirk, const char* want_status, bool want_dirty_rect_is_empty) { wuffs_gif__decoder dec; @@ -477,6 +478,9 @@ const char* do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src, if (status) { RETURN_FAIL("initialize: \"%s\"", status); } + if (quirk) { + wuffs_gif__decoder__set_quirk_enabled(&dec, quirk, true); + } wuffs_base__image_config ic = ((wuffs_base__image_config){}); wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src); @@ -1238,7 +1242,7 @@ const char* test_wuffs_gif_decode_missing_two_src_bytes() { src.meta.wi -= 2; return do_test_wuffs_gif_decode_expecting( - src, wuffs_base__suspension__short_read, false); + src, 0, wuffs_base__suspension__short_read, false); } const char* test_wuffs_gif_decode_multiple_loop_counts() { @@ -1322,7 +1326,7 @@ const char* test_wuffs_gif_decode_pixel_data_none() { } return do_test_wuffs_gif_decode_expecting( - src, wuffs_base__error__not_enough_data, true); + src, 0, wuffs_base__error__not_enough_data, true); } const char* test_wuffs_gif_decode_pixel_data_not_enough() { @@ -1339,10 +1343,10 @@ const char* test_wuffs_gif_decode_pixel_data_not_enough() { } return do_test_wuffs_gif_decode_expecting( - src, wuffs_base__error__not_enough_data, false); + src, 0, wuffs_base__error__not_enough_data, false); } -const char* test_wuffs_gif_decode_pixel_data_too_much() { +const char* test_wuffs_gif_decode_pixel_data_too_much_sans_quirk() { CHECK_FOCUS(__func__); wuffs_base__io_buffer src = ((wuffs_base__io_buffer){ @@ -1356,7 +1360,24 @@ const char* test_wuffs_gif_decode_pixel_data_too_much() { } return do_test_wuffs_gif_decode_expecting( - src, wuffs_base__error__too_much_data, false); + src, 0, wuffs_base__error__too_much_data, false); +} + +const char* test_wuffs_gif_decode_pixel_data_too_much_with_quirk() { + CHECK_FOCUS(__func__); + + wuffs_base__io_buffer src = ((wuffs_base__io_buffer){ + .data = global_src_slice, + }); + + const char* status = + read_file(&src, "test/data/artificial/gif-pixel-data-too-much.gif"); + if (status) { + return status; + } + + return do_test_wuffs_gif_decode_expecting( + src, wuffs_gif__quirk_ignore_too_much_pixel_data, NULL, false); } const char* test_wuffs_gif_frame_dirty_rect() { @@ -2007,7 +2028,8 @@ proc tests[] = { test_wuffs_gif_decode_multiple_loop_counts, // test_wuffs_gif_decode_pixel_data_none, // test_wuffs_gif_decode_pixel_data_not_enough, // - test_wuffs_gif_decode_pixel_data_too_much, // + test_wuffs_gif_decode_pixel_data_too_much_sans_quirk, // + test_wuffs_gif_decode_pixel_data_too_much_with_quirk, // test_wuffs_gif_frame_dirty_rect, // test_wuffs_gif_num_decoded_frame_configs, // test_wuffs_gif_num_decoded_frames, //