Commit b8459c64 authored by Dale Curtis's avatar Dale Curtis Committed by Chromium LUCI CQ

Fix case mismatch between blink::ImageDecoder and MimeUtil.

MimeUtil::IsSupportedImageMimeType() always lowers case before testing
for support, however ImageDecoder::CreateByMimeType() leaves the case
untouched. This change forces lower case in WebCodecs ImageDecoder and
ImageDecoder::CreateByMimeType to ensure consistency.

R=pkasting

Fixed: 1168980
Change-Id: Ibe4202fb56f7b1a0731553662607c76e207467cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2643270
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845877}
parent 7133a470
...@@ -73,7 +73,7 @@ ImageDecoderExternal::ImageDecoderExternal(ScriptState* script_state, ...@@ -73,7 +73,7 @@ ImageDecoderExternal::ImageDecoderExternal(ScriptState* script_state,
options_ = options_ =
init->hasOptions() ? init->options() : ImageBitmapOptions::Create(); init->hasOptions() ? init->options() : ImageBitmapOptions::Create();
mime_type_ = init->type(); mime_type_ = init->type().LowerASCII();
if (!canDecodeType(mime_type_)) { if (!canDecodeType(mime_type_)) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError, exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Unsupported image format"); "Unsupported image format");
...@@ -311,7 +311,7 @@ void ImageDecoderExternal::CreateImageDecoder() { ...@@ -311,7 +311,7 @@ void ImageDecoderExternal::CreateImageDecoder() {
// CreateByImageType() can't fail if we use a supported image type. Which we // CreateByImageType() can't fail if we use a supported image type. Which we
// DCHECK above via canDecodeType(). // DCHECK above via canDecodeType().
DCHECK(decoder_); DCHECK(decoder_) << mime_type_;
} }
void ImageDecoderExternal::MaybeSatisfyPendingDecodes() { void ImageDecoderExternal::MaybeSatisfyPendingDecodes() {
......
...@@ -154,6 +154,17 @@ TEST_F(ImageDecoderTest, DecodeUnsupported) { ...@@ -154,6 +154,17 @@ TEST_F(ImageDecoderTest, DecodeUnsupported) {
EXPECT_TRUE(v8_scope.GetExceptionState().HadException()); EXPECT_TRUE(v8_scope.GetExceptionState().HadException());
} }
TEST_F(ImageDecoderTest, DecoderCreationMixedCaseMimeType) {
V8TestingScope v8_scope;
constexpr char kImageType[] = "image/GiF";
EXPECT_TRUE(ImageDecoderExternal::canDecodeType(kImageType));
auto* decoder =
CreateDecoder(&v8_scope, "images/resources/animated.gif", kImageType);
ASSERT_TRUE(decoder);
ASSERT_FALSE(v8_scope.GetExceptionState().HadException());
EXPECT_EQ(decoder->type(), "image/gif");
}
TEST_F(ImageDecoderTest, DecodeGif) { TEST_F(ImageDecoderTest, DecodeGif) {
V8TestingScope v8_scope; V8TestingScope v8_scope;
constexpr char kImageType[] = "image/gif"; constexpr char kImageType[] = "image/gif";
......
...@@ -181,8 +181,9 @@ std::unique_ptr<ImageDecoder> ImageDecoder::CreateByMimeType( ...@@ -181,8 +181,9 @@ std::unique_ptr<ImageDecoder> ImageDecoder::CreateByMimeType(
CalculateMaxDecodedBytes(high_bit_depth_decoding_option, desired_size); CalculateMaxDecodedBytes(high_bit_depth_decoding_option, desired_size);
// Note: The mime types below should match those supported by // Note: The mime types below should match those supported by
// MimeUtil::IsSupportedImageMimeType(). // MimeUtil::IsSupportedImageMimeType() (which forces lowercase).
std::unique_ptr<ImageDecoder> decoder; std::unique_ptr<ImageDecoder> decoder;
mime_type = mime_type.LowerASCII();
if (mime_type == "image/jpeg" || mime_type == "image/pjpeg" || if (mime_type == "image/jpeg" || mime_type == "image/pjpeg" ||
mime_type == "image/jpg") { mime_type == "image/jpg") {
decoder = std::make_unique<JPEGImageDecoder>(alpha_option, color_behavior, decoder = std::make_unique<JPEGImageDecoder>(alpha_option, color_behavior,
......
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