mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
1 parent
6974c4d629
commit
d7f434c6e4
9 files changed
+162
-43
No files matched your search
+12
-6
@@ -125,6 +125,16 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
|
||||
status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader, workbuf,
|
||||
NULL);
|
||||
|
||||
wuffs_base__rect_ie_u32 frame_rect =
|
||||
wuffs_base__frame_config__bounds(&fc);
|
||||
wuffs_base__rect_ie_u32 dirty_rect =
|
||||
wuffs_gif__decoder__frame_dirty_rect(&dec);
|
||||
if (!wuffs_base__rect_ie_u32__contains_rect(&frame_rect, dirty_rect)) {
|
||||
ret = "internal error: frame_rect does not contain dirty_rect";
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
if ((status != wuffs_base__warning__end_of_data) || !seen_ok) {
|
||||
ret = status;
|
||||
@@ -133,12 +143,8 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
|
||||
}
|
||||
seen_ok = true;
|
||||
|
||||
wuffs_base__rect_ie_u32 frame_rect =
|
||||
wuffs_base__frame_config__bounds(&fc);
|
||||
wuffs_base__rect_ie_u32 dirty_rect =
|
||||
wuffs_gif__decoder__frame_dirty_rect(&dec);
|
||||
if (!wuffs_base__rect_ie_u32__contains_rect(&frame_rect, dirty_rect)) {
|
||||
ret = "internal error: frame_rect does not contain dirty_rect";
|
||||
if (!wuffs_base__rect_ie_u32__equals(&frame_rect, dirty_rect)) {
|
||||
ret = "internal error: frame_rect does not equal dirty_rect";
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ var Statuses = [...]string{
|
||||
`"?initialize falsely claimed already zeroed"`,
|
||||
`"?initialize not called"`,
|
||||
`"?interleaved coroutine calls"`,
|
||||
`"?not enough data"`,
|
||||
}
|
||||
|
||||
// TODO: a collection of forbidden variable names like and, or, not, as, ref,
|
||||
|
||||
@@ -185,6 +185,7 @@ extern const char* wuffs_base__error__disabled_by_previous_error;
|
||||
extern const char* wuffs_base__error__initialize_falsely_claimed_already_zeroed;
|
||||
extern const char* wuffs_base__error__initialize_not_called;
|
||||
extern const char* wuffs_base__error__interleaved_coroutine_calls;
|
||||
extern const char* wuffs_base__error__not_enough_data;
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__status__is_complete(wuffs_base__status z) {
|
||||
@@ -4806,6 +4807,7 @@ const char* wuffs_base__error__initialize_not_called =
|
||||
"?base: initialize not called";
|
||||
const char* wuffs_base__error__interleaved_coroutine_calls =
|
||||
"?base: interleaved coroutine calls";
|
||||
const char* wuffs_base__error__not_enough_data = "?base: not enough data";
|
||||
|
||||
// ---------------- Images
|
||||
|
||||
@@ -10686,6 +10688,14 @@ wuffs_gif__decoder__decode_id_part2(wuffs_gif__decoder* self,
|
||||
label_0_break:;
|
||||
self->private_impl.f_compressed_ri = 0;
|
||||
self->private_impl.f_compressed_wi = 0;
|
||||
if ((self->private_impl.f_dst_y < self->private_impl.f_frame_rect_y1) &&
|
||||
(self->private_impl.f_frame_rect_x0 !=
|
||||
self->private_impl.f_frame_rect_x1) &&
|
||||
(self->private_impl.f_frame_rect_y0 !=
|
||||
self->private_impl.f_frame_rect_y1)) {
|
||||
status = wuffs_base__error__not_enough_data;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
|
||||
@@ -763,7 +763,11 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
|
||||
this.compressed_ri = 0
|
||||
this.compressed_wi = 0
|
||||
|
||||
// TODO: check for "not enough pixel data".
|
||||
if (this.dst_y < this.frame_rect_y1) and
|
||||
(this.frame_rect_x0 != this.frame_rect_x1) and
|
||||
(this.frame_rect_y0 != this.frame_rect_y1) {
|
||||
return base."?not enough data"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.u8) base.status {
|
||||
|
||||
+88
-36
@@ -467,6 +467,48 @@ const char* do_test_wuffs_gif_decode(const char* filename,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src,
|
||||
const char* want_status,
|
||||
bool want_dirty_rect_is_empty) {
|
||||
wuffs_gif__decoder dec;
|
||||
const char* status = wuffs_gif__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
|
||||
if (status) {
|
||||
RETURN_FAIL("initialize: \"%s\"", status);
|
||||
}
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
|
||||
|
||||
status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader);
|
||||
if (status) {
|
||||
RETURN_FAIL("decode_image_config: got \"%s\"", status);
|
||||
}
|
||||
|
||||
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
|
||||
status = wuffs_base__pixel_buffer__set_from_slice(&pb, &ic.pixcfg,
|
||||
global_pixel_slice);
|
||||
if (status) {
|
||||
RETURN_FAIL("set_from_slice: \"%s\"", status);
|
||||
}
|
||||
|
||||
status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader,
|
||||
global_work_slice, NULL);
|
||||
if (status != want_status) {
|
||||
RETURN_FAIL("decode_frame: got \"%s\", want \"%s\"", status, want_status);
|
||||
}
|
||||
|
||||
wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
|
||||
bool dirty_rect_is_empty = wuffs_base__rect_ie_u32__is_empty(&r);
|
||||
if (dirty_rect_is_empty != want_dirty_rect_is_empty) {
|
||||
RETURN_FAIL("dirty_rect.is_empty: got %s, want %s",
|
||||
dirty_rect_is_empty ? "true" : "false",
|
||||
want_dirty_rect_is_empty ? "true" : "false");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_call_interleaved() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
@@ -906,42 +948,8 @@ const char* test_wuffs_gif_decode_missing_two_src_bytes() {
|
||||
}
|
||||
src.meta.wi -= 2;
|
||||
|
||||
wuffs_gif__decoder dec;
|
||||
status = wuffs_gif__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
|
||||
if (status) {
|
||||
RETURN_FAIL("initialize: \"%s\"", status);
|
||||
}
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
|
||||
|
||||
status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader);
|
||||
if (status) {
|
||||
RETURN_FAIL("decode_image_config: got \"%s\"", status);
|
||||
}
|
||||
|
||||
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
|
||||
status = wuffs_base__pixel_buffer__set_from_slice(&pb, &ic.pixcfg,
|
||||
global_pixel_slice);
|
||||
if (status) {
|
||||
RETURN_FAIL("set_from_slice: \"%s\"", status);
|
||||
}
|
||||
|
||||
status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader,
|
||||
global_work_slice, NULL);
|
||||
if (status != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("decode_frame: got \"%s\"", status);
|
||||
}
|
||||
|
||||
// Even we though we haven't seen the 0x00 end-of-block, we should still have
|
||||
// some pixel data.
|
||||
wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
|
||||
if (wuffs_base__rect_ie_u32__is_empty(&r)) {
|
||||
RETURN_FAIL("dirty_rect: got empty, want non-empty");
|
||||
}
|
||||
return NULL;
|
||||
return do_test_wuffs_gif_decode_expecting(
|
||||
src, wuffs_base__suspension__short_read, false);
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_multiple_loop_counts() {
|
||||
@@ -1011,6 +1019,48 @@ const char* test_wuffs_gif_decode_multiple_loop_counts() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_not_enough_data() {
|
||||
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-not-enough-data.gif");
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// TODO: want_dirty_rect_is_empty should probably be false, not true. It's
|
||||
// true because the error sets the decoder state (specifically, the
|
||||
// private_impl.magic field) to WUFFS_BASE__DISABLED, so that
|
||||
// frame_dirty_rect returns the zero value (an empty rect).
|
||||
//
|
||||
// Perhaps "not enough data" should be a warning, not an error??
|
||||
//
|
||||
// Ditto for the "too much data" test.
|
||||
return do_test_wuffs_gif_decode_expecting(
|
||||
src, wuffs_base__error__not_enough_data, true);
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_too_much_data() {
|
||||
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-too-much-data.gif");
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return do_test_wuffs_gif_decode_expecting(
|
||||
src, wuffs_gif__error__too_much_pixel_data, true);
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_frame_dirty_rect() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
@@ -1627,6 +1677,8 @@ proc tests[] = {
|
||||
test_wuffs_gif_decode_input_is_a_png, //
|
||||
test_wuffs_gif_decode_missing_two_src_bytes, //
|
||||
test_wuffs_gif_decode_multiple_loop_counts, //
|
||||
test_wuffs_gif_decode_not_enough_data, //
|
||||
test_wuffs_gif_decode_too_much_data, //
|
||||
test_wuffs_gif_frame_dirty_rect, //
|
||||
test_wuffs_gif_num_decoded_frame_configs, //
|
||||
test_wuffs_gif_num_decoded_frames, //
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 B |
@@ -0,0 +1,23 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make gif
|
||||
|
||||
header
|
||||
|
||||
image {
|
||||
imageWidthHeight 2 2
|
||||
palette {
|
||||
0x00 0x00 0xFF
|
||||
0x11 0x00 0xFF
|
||||
0x22 0x00 0xFF
|
||||
0x33 0x00 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 0 0 2 2
|
||||
}
|
||||
# The frame is 4 pixels, but we only supply 1.
|
||||
lzw 2 0x00
|
||||
|
||||
trailer
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 41 B |
@@ -0,0 +1,23 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make gif
|
||||
|
||||
header
|
||||
|
||||
image {
|
||||
imageWidthHeight 2 2
|
||||
palette {
|
||||
0x00 0x00 0xFF
|
||||
0x11 0x00 0xFF
|
||||
0x22 0x00 0xFF
|
||||
0x33 0x00 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 0 0 2 2
|
||||
}
|
||||
# The frame is 4 pixels, but we supply 5.
|
||||
lzw 2 0x00 0x00 0x00 0x00 0x00
|
||||
|
||||
trailer
|
||||
Reference in new issue
Block a user