From 9437d1a265b0900b5751e579a8adbc2df9bf1f89 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 17 Oct 2021 13:22:01 +1100 Subject: [PATCH] Tighten magic number guessing for WBMP --- internal/cgen/base/magic-submodule.c | 9 +++++++++ release/c/wuffs-unsupported-snapshot.c | 9 +++++++++ test/nia-checksums-of-data.txt | 5 ----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/internal/cgen/base/magic-submodule.c b/internal/cgen/base/magic-submodule.c index 32f65005..90782bc6 100644 --- a/internal/cgen/base/magic-submodule.c +++ b/internal/cgen/base/magic-submodule.c @@ -89,6 +89,15 @@ match: return 0x5750384C; // 'WP8L'be } } + } else if (fourcc == 0x57424D50) { // 'WBMP'be + 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; + } } return fourcc; } diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index a24f9ae9..c8a96ea2 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -15289,6 +15289,15 @@ match: return 0x5750384C; // 'WP8L'be } } + } else if (fourcc == 0x57424D50) { // 'WBMP'be + 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; + } } return fourcc; } diff --git a/test/nia-checksums-of-data.txt b/test/nia-checksums-of-data.txt index 648965bc..0197c9c0 100644 --- a/test/nia-checksums-of-data.txt +++ b/test/nia-checksums-of-data.txt @@ -1,7 +1,6 @@ # Generated by script/print-nia-checksums.sh d3bb0beb test/data/DCI-P3-D65.icc 76e40058 test/data/animated-red-blue.gif -912861f4 test/data/archive.iso f9a10dac test/data/artificial/gif-background-color.gif 36e7d9c7 test/data/artificial/gif-empty-palette.gif db4c30eb test/data/artificial/gif-frame-out-of-bounds.gif @@ -16,7 +15,6 @@ fdcc644f test/data/artificial/gif-metadata-full.gif f50d1d50 test/data/artificial/gif-small-frame-interlaced.gif beaec397 test/data/artificial/gif-transparent-index.gif 6ec818c3 test/data/artificial/gif-zero-width-frame.gif -912861f4 test/data/australian-abc-local-stations.tokens 076cb375 test/data/bricks-color.bmp 076cb375 test/data/bricks-color.png f36c2e80 test/data/bricks-dither.bmp @@ -31,7 +29,6 @@ c2bce675 test/data/bricks-gray.png b641fef2 test/data/bricks-nodither.gif 7aebfe6c test/data/bricks-nodither.png ae2e547d test/data/bricks-nodither.wbmp -912861f4 test/data/cbor-rfc-7049-examples.tokens 3014b4c0 test/data/gifplayer-muybridge.gif 030f5a48 test/data/harvesters.bmp 0d213dc4 test/data/harvesters.gif @@ -53,8 +50,6 @@ a80781a1 test/data/hippopotamus.interlaced.truncated.gif 7e6acf01 test/data/hippopotamus.masked-with-muybridge.png 21e17862 test/data/hippopotamus.regular.gif dcbb225a test/data/hippopotamus.regular.png -aa7e021c test/data/json-quirks.tokens -912861f4 test/data/json-things.unformatted.tokens 2dccfe56 test/data/muybridge-frame-000.wbmp db2733f5 test/data/muybridge.gif bf7e8c96 test/data/pjw-thumbnail.bmp