Fix parsing 0 length GIF metadata

This commit is contained in:
Nigel Tao committed 2019-08-31 08:20:18 +10:00
1 parent e75fe256b2
commit f379f7f905
7 files changed
+108 -45

No files matched your search

+18 -7
View File
@@ -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