mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Fix parsing 0 length GIF metadata
This commit is contained in:
1 parent
e75fe256b2
commit
f379f7f905
7 files changed
+108
-45
No files matched your search
@@ -8911,26 +8911,19 @@ wuffs_gif__decoder__ack_metadata_chunk(wuffs_gif__decoder* self,
|
||||
status = wuffs_base__error__bad_i_o_position;
|
||||
goto exit;
|
||||
}
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__suspension__short_read;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc_value == 1481461792) {
|
||||
self->private_impl.f_metadata_chunk_length_value =
|
||||
(((uint64_t)(wuffs_base__load_u8be(iop_a_src))) + 1);
|
||||
if (self->private_impl.f_metadata_chunk_length_value > 1) {
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(
|
||||
wuffs_base__u64__sat_add(a_src->meta.pos,
|
||||
((uint64_t)(iop_a_src - io0_a_src))),
|
||||
self->private_impl.f_metadata_chunk_length_value);
|
||||
status = wuffs_base__warning__metadata_reported;
|
||||
goto ok;
|
||||
if (self->private_impl.f_metadata_chunk_length_value > 0) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__suspension__short_read;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
} else {
|
||||
self->private_impl.f_metadata_chunk_length_value =
|
||||
((uint64_t)(wuffs_base__load_u8be(iop_a_src)));
|
||||
if (self->private_impl.f_metadata_chunk_length_value > 0) {
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
if (self->private_impl.f_metadata_fourcc_value == 1481461792) {
|
||||
self->private_impl.f_metadata_chunk_length_value += 1;
|
||||
} else {
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
}
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(
|
||||
wuffs_base__u64__sat_add(a_src->meta.pos,
|
||||
((uint64_t)(iop_a_src - io0_a_src))),
|
||||
@@ -8938,8 +8931,8 @@ wuffs_gif__decoder__ack_metadata_chunk(wuffs_gif__decoder* self,
|
||||
status = wuffs_base__warning__metadata_reported;
|
||||
goto ok;
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
}
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_metadata_fourcc_value = 0;
|
||||
self->private_impl.f_metadata_io_position = 0;
|
||||
@@ -10245,7 +10238,12 @@ wuffs_gif__decoder__decode_ae(wuffs_gif__decoder* self,
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
}
|
||||
self->private_impl.f_metadata_chunk_length_value =
|
||||
(((uint64_t)(wuffs_base__load_u8be(iop_a_src))) + 1);
|
||||
((uint64_t)(wuffs_base__load_u8be(iop_a_src)));
|
||||
if (self->private_impl.f_metadata_chunk_length_value > 0) {
|
||||
self->private_impl.f_metadata_chunk_length_value += 1;
|
||||
} else {
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc_value = 1481461792;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(
|
||||
wuffs_base__u64__sat_add(a_src->meta.pos,
|
||||
|
||||
+28
-20
@@ -310,30 +310,33 @@ pub func decoder.ack_metadata_chunk?(src base.io_reader) {
|
||||
if args.src.position() <> this.metadata_io_position {
|
||||
return base."#bad I/O position"
|
||||
}
|
||||
while args.src.available() <= 0,
|
||||
post args.src.available() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
}
|
||||
|
||||
if this.metadata_fourcc_value == 0x584D5020 { // "XMP "
|
||||
// The +1 is because XMP metadata's encoding includes each block's leading
|
||||
// byte (the block size) as part of the metadata passed to the caller.
|
||||
this.metadata_chunk_length_value = args.src.peek_u8_as_u64() + 1
|
||||
if this.metadata_chunk_length_value > 1 {
|
||||
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||
return base."@metadata reported"
|
||||
if this.metadata_chunk_length_value > 0 {
|
||||
while args.src.available() <= 0,
|
||||
post args.src.available() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
}
|
||||
} else {
|
||||
|
||||
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
|
||||
if this.metadata_chunk_length_value > 0 {
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||
if this.metadata_fourcc_value == 0x584D5020 { // "XMP "
|
||||
// The +1 is because XMP metadata's encoding includes each
|
||||
// block's leading byte (the block size) as part of the
|
||||
// metadata passed to the caller.
|
||||
this.metadata_chunk_length_value += 1
|
||||
} else {
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
}
|
||||
this.metadata_io_position =
|
||||
args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
// Consume the '\x00' that means a zero-length block.
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
}
|
||||
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
this.call_sequence = 2
|
||||
this.metadata_fourcc_value = 0
|
||||
this.metadata_io_position = 0
|
||||
@@ -797,10 +800,15 @@ pri func decoder.decode_ae?(src base.io_reader) {
|
||||
{
|
||||
yield? base."$short read"
|
||||
}
|
||||
// The +1 is because XMP metadata's encoding includes each block's
|
||||
// leading byte (the block size) as part of the metadata passed to
|
||||
// the caller.
|
||||
this.metadata_chunk_length_value = args.src.peek_u8_as_u64() + 1
|
||||
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
|
||||
if this.metadata_chunk_length_value > 0 {
|
||||
// The +1 is because XMP metadata's encoding includes each
|
||||
// block's leading byte (the block size) as part of the
|
||||
// metadata passed to the caller.
|
||||
this.metadata_chunk_length_value += 1
|
||||
} else {
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
}
|
||||
this.metadata_fourcc_value = 0x584D5020 // "XMP "
|
||||
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||
this.call_sequence = 1
|
||||
|
||||
+18
-7
@@ -1255,14 +1255,14 @@ const char* test_wuffs_gif_decode_input_is_a_png() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_metadata() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
const char* do_test_wuffs_gif_decode_metadata(bool full) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = global_src_slice,
|
||||
});
|
||||
|
||||
const char* status = read_file(&src, "test/data/artificial/gif-metadata.gif");
|
||||
const char* status =
|
||||
read_file(&src, full ? "test/data/artificial/gif-metadata-full.gif"
|
||||
: "test/data/artificial/gif-metadata-empty.gif");
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
@@ -1311,11 +1311,11 @@ const char* test_wuffs_gif_decode_metadata() {
|
||||
|
||||
switch (wuffs_gif__decoder__metadata_fourcc(&dec)) {
|
||||
case WUFFS_BASE__FOURCC__ICCP:
|
||||
want = "\x16\x26\x36\x46\x56\x76\x86\x96";
|
||||
want = full ? "\x16\x26\x36\x46\x56\x76\x86\x96" : "";
|
||||
seen_iccp = true;
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__XMP:
|
||||
want = "\x05\x17\x27\x37\x47\x57\x03\x77\x87\x97";
|
||||
want = full ? "\x05\x17\x27\x37\x47\x57\x03\x77\x87\x97" : "";
|
||||
seen_xmp = true;
|
||||
break;
|
||||
default:
|
||||
@@ -1412,6 +1412,16 @@ const char* test_wuffs_gif_decode_metadata() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_metadata_empty() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_wuffs_gif_decode_metadata(false);
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_metadata_full() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_wuffs_gif_decode_metadata(true);
|
||||
}
|
||||
|
||||
const char* test_wuffs_gif_decode_missing_two_src_bytes() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
@@ -2242,7 +2252,8 @@ proc tests[] = {
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_small_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_png, //
|
||||
test_wuffs_gif_decode_metadata, //
|
||||
test_wuffs_gif_decode_metadata_empty, //
|
||||
test_wuffs_gif_decode_metadata_full, //
|
||||
test_wuffs_gif_decode_missing_two_src_bytes, //
|
||||
test_wuffs_gif_decode_multiple_graphic_controls, //
|
||||
test_wuffs_gif_decode_multiple_loop_counts, //
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 90 B |
@@ -0,0 +1,46 @@
|
||||
# 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
|
||||
}
|
||||
}
|
||||
|
||||
# ICCP metadata.
|
||||
#
|
||||
# Extension (Application Extension), 11 bytes for AI and AAC.
|
||||
bytes 0x21 0xFF 0x0B
|
||||
# Application Identifier "ICCRGBG1".
|
||||
bytes 0x49 0x43 0x43 0x52 0x47 0x42 0x47 0x31
|
||||
# Application Authentication Code "012".
|
||||
bytes 0x30 0x31 0x32
|
||||
# Block Terminator.
|
||||
bytes 0x00
|
||||
|
||||
# XMP metadata.
|
||||
#
|
||||
# Extension (Application Extension), 11 bytes for AI and AAC.
|
||||
bytes 0x21 0xFF 0x0B
|
||||
# Application Identifier "XMP Data".
|
||||
bytes 0x58 0x4D 0x50 0x20 0x44 0x61 0x74 0x61
|
||||
# Application Authentication Code "XMP".
|
||||
bytes 0x58 0x4D 0x50
|
||||
# Block Terminator.
|
||||
bytes 0x00
|
||||
|
||||
loopCount 2000
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 1 0 1 1
|
||||
}
|
||||
lzw 4 0x01
|
||||
|
||||
trailer
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 110 B |
Reference in new issue
Block a user