Commit 22af5afe authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Fix WebP sniff pattern

The current pattern wouldn't be able to sniff the 'lossless' and
'extended' WebP formats.

Adjust the pattern to match the one described by [1].

[1] https://mimesniff.spec.whatwg.org/#matching-an-image-type-pattern

Bug: 889420
Change-Id: I4b5a73d4d9477502d58df7460b9494e6540a59f3
Reviewed-on: https://chromium-review.googlesource.com/1248782Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#595273}
parent 20153791
......@@ -152,7 +152,7 @@ static const MagicNumber kMagicNumbers[] = {
MAGIC_NUMBER("image/tiff", "II*"),
MAGIC_NUMBER("image/tiff", "MM\x00*"),
MAGIC_NUMBER("audio/mpeg", "ID3"),
MAGIC_NUMBER("image/webp", "RIFF....WEBPVP8 "),
MAGIC_NUMBER("image/webp", "RIFF....WEBPVP"),
MAGIC_NUMBER("video/webm", "\x1A\x45\xDF\xA3"),
MAGIC_NUMBER("application/zip", "PK\x03\x04"),
MAGIC_NUMBER("application/x-rar-compressed", "Rar!\x1A\x07\x00"),
......
......@@ -458,6 +458,27 @@ TEST(MimeSnifferTest, AudioVideoTest) {
mime_type.clear();
}
TEST(MimeSnifferTest, ImageTest) {
std::string mime_type;
const char kWebPSimpleFormat[] = "RIFF\xee\x81\x00\x00WEBPVP8 ";
EXPECT_TRUE(SniffMimeTypeFromLocalData(
kWebPSimpleFormat, sizeof(kWebPSimpleFormat) - 1, &mime_type));
EXPECT_EQ("image/webp", mime_type);
mime_type.clear();
const char kWebPLosslessFormat[] = "RIFF\xee\x81\x00\x00WEBPVP8L";
EXPECT_TRUE(SniffMimeTypeFromLocalData(
kWebPLosslessFormat, sizeof(kWebPLosslessFormat) - 1, &mime_type));
EXPECT_EQ("image/webp", mime_type);
mime_type.clear();
const char kWebPExtendedFormat[] = "RIFF\xee\x81\x00\x00WEBPVP8X";
EXPECT_TRUE(SniffMimeTypeFromLocalData(
kWebPExtendedFormat, sizeof(kWebPExtendedFormat) - 1, &mime_type));
EXPECT_EQ("image/webp", mime_type);
mime_type.clear();
}
// The tests need char parameters, but the ranges to test include 0xFF, and some
// platforms have signed chars and are noisy about it. Using an int parameter
// and casting it to char inside the test case solves both these problems.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment