From 787ff21cc784ede18ebf3d6b8c8406c5c4b4ab17 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 13 May 2022 11:01:28 +1000 Subject: [PATCH] Let magic_number_guess_fourcc sniff compression --- internal/cgen/base/magic-submodule.c | 9 +++++++-- release/c/wuffs-unsupported-snapshot.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/cgen/base/magic-submodule.c b/internal/cgen/base/magic-submodule.c index f70ab937..47fabeef 100644 --- a/internal/cgen/base/magic-submodule.c +++ b/internal/cgen/base/magic-submodule.c @@ -139,8 +139,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, // strings). The strings may contain NUL bytes, so the "const char* magic" // value starts with the length-minus-1 of the 'magic number'. // - // Keep it sorted by magic[1], then magic[0] descending and finally by - // magic[2:]. When multiple entries match, the longest one wins. + // Keep it sorted by magic[1], then magic[0] descending (prioritizing longer + // matches) and finally by magic[2:]. When multiple entries match, the + // longest one wins. // // The fourcc field might be negated, in which case there's further // specialization (see § below). @@ -149,6 +150,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, const char* magic; } table[] = { {-0x30302020, "\x01\x00\x00"}, // '00 'be + {+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ + {+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD + {+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2 {+0x424D5020, "\x01\x42\x4D"}, // BMP {+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF {+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) @@ -156,6 +160,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, {-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF {+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI + {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG {+0x4A504547, "\x01\xFF\xD8"}, // JPEG }; diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index d2166a02..8b7460b1 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -16250,8 +16250,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, // strings). The strings may contain NUL bytes, so the "const char* magic" // value starts with the length-minus-1 of the 'magic number'. // - // Keep it sorted by magic[1], then magic[0] descending and finally by - // magic[2:]. When multiple entries match, the longest one wins. + // Keep it sorted by magic[1], then magic[0] descending (prioritizing longer + // matches) and finally by magic[2:]. When multiple entries match, the + // longest one wins. // // The fourcc field might be negated, in which case there's further // specialization (see § below). @@ -16260,6 +16261,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, const char* magic; } table[] = { {-0x30302020, "\x01\x00\x00"}, // '00 'be + {+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ + {+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD + {+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2 {+0x424D5020, "\x01\x42\x4D"}, // BMP {+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF {+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian) @@ -16267,6 +16271,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, {-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF {+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI + {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG {+0x4A504547, "\x01\xFF\xD8"}, // JPEG };