mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Loosen what std/gif allows as the trailer byte
This commit is contained in:
1 parent
ee60af58fb
commit
f9a90d8ade
5 files changed
+71
-32
No files matched your search
@@ -5644,7 +5644,6 @@ extern "C" {
|
|||||||
|
|
||||||
// ---------------- Status Codes
|
// ---------------- Status Codes
|
||||||
|
|
||||||
extern const char* wuffs_gif__error__bad_block;
|
|
||||||
extern const char* wuffs_gif__error__bad_extension_label;
|
extern const char* wuffs_gif__error__bad_extension_label;
|
||||||
extern const char* wuffs_gif__error__bad_frame_size;
|
extern const char* wuffs_gif__error__bad_frame_size;
|
||||||
extern const char* wuffs_gif__error__bad_graphic_control;
|
extern const char* wuffs_gif__error__bad_graphic_control;
|
||||||
@@ -16874,7 +16873,6 @@ wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self) {
|
|||||||
|
|
||||||
// ---------------- Status Codes Implementations
|
// ---------------- Status Codes Implementations
|
||||||
|
|
||||||
const char* wuffs_gif__error__bad_block = "#gif: bad block";
|
|
||||||
const char* wuffs_gif__error__bad_extension_label = "#gif: bad extension label";
|
const char* wuffs_gif__error__bad_extension_label = "#gif: bad extension label";
|
||||||
const char* wuffs_gif__error__bad_frame_size = "#gif: bad frame size";
|
const char* wuffs_gif__error__bad_frame_size = "#gif: bad frame size";
|
||||||
const char* wuffs_gif__error__bad_graphic_control = "#gif: bad graphic control";
|
const char* wuffs_gif__error__bad_graphic_control = "#gif: bad graphic control";
|
||||||
@@ -18055,7 +18053,7 @@ wuffs_gif__config_decoder__decode_up_to_id_part1(
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
} else if (v_block_type == 59) {
|
} else {
|
||||||
if (self->private_impl.f_delayed_num_decoded_frames) {
|
if (self->private_impl.f_delayed_num_decoded_frames) {
|
||||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||||
wuffs_base__u64__sat_add_indirect(
|
wuffs_base__u64__sat_add_indirect(
|
||||||
@@ -18063,9 +18061,6 @@ wuffs_gif__config_decoder__decode_up_to_id_part1(
|
|||||||
}
|
}
|
||||||
self->private_impl.f_end_of_data = true;
|
self->private_impl.f_end_of_data = true;
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
} else {
|
|
||||||
status = wuffs_base__make_status(wuffs_gif__error__bad_block);
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
label__0__break:;
|
label__0__break:;
|
||||||
@@ -19928,7 +19923,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(wuffs_gif__decoder* self,
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
} else if (v_block_type == 59) {
|
} else {
|
||||||
if (self->private_impl.f_delayed_num_decoded_frames) {
|
if (self->private_impl.f_delayed_num_decoded_frames) {
|
||||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||||
wuffs_base__u64__sat_add_indirect(
|
wuffs_base__u64__sat_add_indirect(
|
||||||
@@ -19936,9 +19931,6 @@ wuffs_gif__decoder__decode_up_to_id_part1(wuffs_gif__decoder* self,
|
|||||||
}
|
}
|
||||||
self->private_impl.f_end_of_data = true;
|
self->private_impl.f_end_of_data = true;
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
} else {
|
|
||||||
status = wuffs_base__make_status(wuffs_gif__error__bad_block);
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
label__0__break:;
|
label__0__break:;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
use "std/lzw"
|
use "std/lzw"
|
||||||
|
|
||||||
pub status "#bad block"
|
|
||||||
pub status "#bad extension label"
|
pub status "#bad extension label"
|
||||||
pub status "#bad frame size"
|
pub status "#bad frame size"
|
||||||
pub status "#bad graphic control"
|
pub status "#bad graphic control"
|
||||||
|
|||||||
@@ -423,15 +423,25 @@ pri func config_decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
|||||||
}
|
}
|
||||||
this.decode_id_part0?(src: args.src)
|
this.decode_id_part0?(src: args.src)
|
||||||
break
|
break
|
||||||
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
|
} else {
|
||||||
|
// If we don't have 0x21 or 0x2C then, according to the spec, the
|
||||||
|
// only valid byte is 0x3B, called the "Trailer". In practice, some
|
||||||
|
// other popular decoders allow anything (other than 0x21 or 0x2C)
|
||||||
|
// to be equivalent to 0x3B, which ends the animated GIF image, and
|
||||||
|
// we do likewise here. Some real world GIF files that exhibit this
|
||||||
|
// are at https://github.com/golang/go/issues/38853
|
||||||
|
//
|
||||||
|
// Chromium's decoder
|
||||||
|
// https://skia.googlesource.com/libgifcodec/+/c002ec500aba1e1b0189547629787cb02db78193/SkGifImageReader.cpp#563
|
||||||
|
//
|
||||||
|
// Firefox's decoder
|
||||||
|
// https://dxr.mozilla.org/mozilla-central/rev/93a33cb7f2369ac4f1d1f2ac97ec14ba60e1e7d7/image/decoders/nsGIFDecoder2.cpp#569
|
||||||
if this.delayed_num_decoded_frames {
|
if this.delayed_num_decoded_frames {
|
||||||
this.delayed_num_decoded_frames = false
|
this.delayed_num_decoded_frames = false
|
||||||
this.num_decoded_frames_value ~sat+= 1
|
this.num_decoded_frames_value ~sat+= 1
|
||||||
}
|
}
|
||||||
this.end_of_data = true
|
this.end_of_data = true
|
||||||
break
|
break
|
||||||
} else {
|
|
||||||
return "#bad block"
|
|
||||||
}
|
}
|
||||||
} endwhile
|
} endwhile
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,15 +498,25 @@ pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
|||||||
}
|
}
|
||||||
this.decode_id_part0?(src: args.src)
|
this.decode_id_part0?(src: args.src)
|
||||||
break
|
break
|
||||||
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
|
} else {
|
||||||
|
// If we don't have 0x21 or 0x2C then, according to the spec, the
|
||||||
|
// only valid byte is 0x3B, called the "Trailer". In practice, some
|
||||||
|
// other popular decoders allow anything (other than 0x21 or 0x2C)
|
||||||
|
// to be equivalent to 0x3B, which ends the animated GIF image, and
|
||||||
|
// we do likewise here. Some real world GIF files that exhibit this
|
||||||
|
// are at https://github.com/golang/go/issues/38853
|
||||||
|
//
|
||||||
|
// Chromium's decoder
|
||||||
|
// https://skia.googlesource.com/libgifcodec/+/c002ec500aba1e1b0189547629787cb02db78193/SkGifImageReader.cpp#563
|
||||||
|
//
|
||||||
|
// Firefox's decoder
|
||||||
|
// https://dxr.mozilla.org/mozilla-central/rev/93a33cb7f2369ac4f1d1f2ac97ec14ba60e1e7d7/image/decoders/nsGIFDecoder2.cpp#569
|
||||||
if this.delayed_num_decoded_frames {
|
if this.delayed_num_decoded_frames {
|
||||||
this.delayed_num_decoded_frames = false
|
this.delayed_num_decoded_frames = false
|
||||||
this.num_decoded_frames_value ~sat+= 1
|
this.num_decoded_frames_value ~sat+= 1
|
||||||
}
|
}
|
||||||
this.end_of_data = true
|
this.end_of_data = true
|
||||||
break
|
break
|
||||||
} else {
|
|
||||||
return "#bad block"
|
|
||||||
}
|
}
|
||||||
} endwhile
|
} endwhile
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-15
@@ -491,11 +491,13 @@ do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src,
|
|||||||
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
||||||
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
||||||
|
|
||||||
wuffs_base__status status = wuffs_gif__decoder__decode_frame(
|
{
|
||||||
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
|
wuffs_base__status status = wuffs_gif__decoder__decode_frame(
|
||||||
if (status.repr != want_status) {
|
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
|
||||||
RETURN_FAIL("decode_frame: have \"%s\", want \"%s\"", status.repr,
|
if (status.repr != want_status) {
|
||||||
want_status);
|
RETURN_FAIL("decode_frame #0: have \"%s\", want \"%s\"", status.repr,
|
||||||
|
want_status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
|
wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
|
||||||
@@ -505,6 +507,16 @@ do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src,
|
|||||||
dirty_rect_is_empty ? "true" : "false",
|
dirty_rect_is_empty ? "true" : "false",
|
||||||
want_dirty_rect_is_empty ? "true" : "false");
|
want_dirty_rect_is_empty ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (want_status == NULL) {
|
||||||
|
wuffs_base__status status = wuffs_gif__decoder__decode_frame(
|
||||||
|
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
|
||||||
|
if (status.repr != wuffs_base__note__end_of_data) {
|
||||||
|
RETURN_FAIL("decode_frame #1: have \"%s\", want \"%s\"", status.repr,
|
||||||
|
wuffs_base__note__end_of_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,18 +715,14 @@ test_wuffs_gif_decode_delay_num_frames_decoded() {
|
|||||||
.data = g_src_slice_u8,
|
.data = g_src_slice_u8,
|
||||||
});
|
});
|
||||||
CHECK_STRING(read_file(&src, "test/data/animated-red-blue.gif"));
|
CHECK_STRING(read_file(&src, "test/data/animated-red-blue.gif"));
|
||||||
if (src.meta.wi < 1) {
|
|
||||||
return "src file is too short";
|
|
||||||
}
|
|
||||||
|
|
||||||
// A GIF image should end with the 0x3B Trailer byte.
|
// Truncate the final 0x3B trailer byte.
|
||||||
if (src.data.ptr[src.meta.wi - 1] != 0x3B) {
|
if (src.meta.wi <= 0) {
|
||||||
RETURN_FAIL("final byte: have 0x%02X, want 0x%02X",
|
return "src file is too short";
|
||||||
src.data.ptr[src.meta.wi - 1], 0x3B);
|
} else if (src.data.ptr[src.meta.wi - 1] != 0x3B) {
|
||||||
|
return "src file does not end with 0x3B";
|
||||||
}
|
}
|
||||||
// Replace that final byte with something invalid: neither 0x21 (Extension
|
src.meta.wi--;
|
||||||
// Introducer), 0x2C (Image Separator) or 0x3B (Trailer).
|
|
||||||
src.data.ptr[src.meta.wi - 1] = 0x99;
|
|
||||||
|
|
||||||
int q;
|
int q;
|
||||||
for (q = 0; q < 2; q++) {
|
for (q = 0; q < 2; q++) {
|
||||||
@@ -1593,6 +1601,25 @@ test_wuffs_gif_decode_multiple_loop_counts() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* //
|
||||||
|
test_wuffs_gif_decode_nul_byte_trailer() {
|
||||||
|
CHECK_FOCUS(__func__);
|
||||||
|
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||||
|
.data = g_src_slice_u8,
|
||||||
|
});
|
||||||
|
CHECK_STRING(read_file(&src, "test/data/pjw-thumbnail.gif"));
|
||||||
|
|
||||||
|
// Change the final 0x3B trailer byte to 0x00.
|
||||||
|
if (src.meta.wi <= 0) {
|
||||||
|
return "src file is too short";
|
||||||
|
} else if (src.data.ptr[src.meta.wi - 1] != 0x3B) {
|
||||||
|
return "src file does not end with 0x3B";
|
||||||
|
}
|
||||||
|
src.data.ptr[src.meta.wi - 1] = 0x00;
|
||||||
|
|
||||||
|
return do_test_wuffs_gif_decode_expecting(src, 0, NULL, false);
|
||||||
|
}
|
||||||
|
|
||||||
const char* //
|
const char* //
|
||||||
test_wuffs_gif_decode_pixel_data_none() {
|
test_wuffs_gif_decode_pixel_data_none() {
|
||||||
CHECK_FOCUS(__func__);
|
CHECK_FOCUS(__func__);
|
||||||
@@ -2409,6 +2436,7 @@ proc g_tests[] = {
|
|||||||
test_wuffs_gif_decode_missing_two_src_bytes,
|
test_wuffs_gif_decode_missing_two_src_bytes,
|
||||||
test_wuffs_gif_decode_multiple_graphic_controls,
|
test_wuffs_gif_decode_multiple_graphic_controls,
|
||||||
test_wuffs_gif_decode_multiple_loop_counts,
|
test_wuffs_gif_decode_multiple_loop_counts,
|
||||||
|
test_wuffs_gif_decode_nul_byte_trailer,
|
||||||
test_wuffs_gif_decode_pixel_data_none,
|
test_wuffs_gif_decode_pixel_data_none,
|
||||||
test_wuffs_gif_decode_pixel_data_not_enough,
|
test_wuffs_gif_decode_pixel_data_not_enough,
|
||||||
test_wuffs_gif_decode_pixel_data_too_much_sans_quirk,
|
test_wuffs_gif_decode_pixel_data_too_much_sans_quirk,
|
||||||
|
|||||||
Reference in new issue
Block a user