diff --git a/internal/cgen/base/magic-submodule.c b/internal/cgen/base/magic-submodule.c index 90782bc6..cac95062 100644 --- a/internal/cgen/base/magic-submodule.c +++ b/internal/cgen/base/magic-submodule.c @@ -26,7 +26,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) { int32_t fourcc; const char* magic; } table[] = { - {0x57424D50, "\x01\x00\x00"}, // WBMP + {0x30302020, "\x01\x00\x00"}, // '00 'be (see § below) {0x424D5020, "\x01\x42\x4D"}, // BMP {0x47494620, "\x03\x47\x49\x46\x38"}, // GIF {0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) @@ -89,15 +89,20 @@ match: return 0x5750384C; // 'WP8L'be } } - } else if (fourcc == 0x57424D50) { // 'WBMP'be + } else if (fourcc == 0x30302020) { // '00 'be + // Binary data starting with multiple 0x00 NUL bytes is quite common. if (prefix.len < 4) { return -1; - } else if ((prefix.ptr[2] == 0x00) || - ((prefix.ptr[2] < 0x80) && (prefix.ptr[3] == 0x00))) { - // Reject 0-width or 0-height WBMP images. Binary data starting with - // multiple 0x00 NUL bytes is quite common. - return 0; + } else if ((prefix.ptr[2] != 0x00) && + ((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) { + // Roughly speaking, this could be a non-degenerate (non-0-width and + // non-0-height) WBMP image. + return 0x57424D50; // 'WBMP'be + } else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) && + (prefix.ptr[3] == 0x00)) { + return 0x49434F20; // 'ICO 'be } + return 0; } return fourcc; } diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index fd34bf34..a59a1297 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -15411,7 +15411,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) { int32_t fourcc; const char* magic; } table[] = { - {0x57424D50, "\x01\x00\x00"}, // WBMP + {0x30302020, "\x01\x00\x00"}, // '00 'be (see § below) {0x424D5020, "\x01\x42\x4D"}, // BMP {0x47494620, "\x03\x47\x49\x46\x38"}, // GIF {0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) @@ -15474,15 +15474,20 @@ match: return 0x5750384C; // 'WP8L'be } } - } else if (fourcc == 0x57424D50) { // 'WBMP'be + } else if (fourcc == 0x30302020) { // '00 'be + // Binary data starting with multiple 0x00 NUL bytes is quite common. if (prefix.len < 4) { return -1; - } else if ((prefix.ptr[2] == 0x00) || - ((prefix.ptr[2] < 0x80) && (prefix.ptr[3] == 0x00))) { - // Reject 0-width or 0-height WBMP images. Binary data starting with - // multiple 0x00 NUL bytes is quite common. - return 0; + } else if ((prefix.ptr[2] != 0x00) && + ((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) { + // Roughly speaking, this could be a non-degenerate (non-0-width and + // non-0-height) WBMP image. + return 0x57424D50; // 'WBMP'be + } else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) && + (prefix.ptr[3] == 0x00)) { + return 0x49434F20; // 'ICO 'be } + return 0; } return fourcc; } diff --git a/test/data/README.md b/test/data/README.md index fd1bf401..d3d43491 100644 --- a/test/data/README.md +++ b/test/data/README.md @@ -6,7 +6,7 @@ files were generated by `script/extract-palette-indexes.go`. The `*.tokens` files were generated by `script/print-json-token-debug-format.c`. The `*.jpeg` files are usually the canonical versions of the test/data images, -and other versions (`*.bmp`, `*.gif`, `*.png`, `*.tiff`) were generated by +and other versions (`*.bmp`, `*.gif`, `*.png` etc) were usually generated by ImageMagick's `convert` command line tool. The `*.wbmp` versions were generated by the `script/convert-png-to-wbmp.go` command line tool. The `*.webp` versions were generated by the cwebp command line tool. The `*.no-ancillary.png` files diff --git a/test/data/hippopotamus.regular.ico b/test/data/hippopotamus.regular.ico new file mode 100644 index 00000000..18b0b83e Binary files /dev/null and b/test/data/hippopotamus.regular.ico differ