Commit 1d8e7de3 authored by Juanmi Huertas's avatar Juanmi Huertas Committed by Chromium LUCI CQ

Checking if resizeWidth or resizeHeight are 0 when creating Bitmap

According to the standard https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html
when creating a new ImageBitmap that has resizeWidth or resizeHeight
equal to 0, it has to throw an exception.

As in some cases, user can provide value between 0 and 1, these will be
rounded down to zero (as according to the standard those resizeWidth and
resizeHeight is a unsigned long, so it cannot have decimal values).

Bug: 1137216
Change-Id: I4a0b241fa8a94cc6b59c77bb1313f7a4d7983733
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636373Reviewed-by: default avatarAaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845407}
parent e6f38d3f
......@@ -144,6 +144,18 @@ ScriptPromise ImageElementBase::CreateImageBitmap(
"No image can be retrieved from the provided element.");
return ScriptPromise();
}
if (options->hasResizeWidth() && options->resizeWidth() == 0) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"The resize width dimension is equal to 0.");
return ScriptPromise();
}
if (options->hasResizeHeight() && options->resizeHeight() == 0) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"The resize width dimension is equal to 0.");
return ScriptPromise();
}
if (auto* svg_image = DynamicTo<SVGImage>(image_content->GetImage())) {
if (!HasDimensionsForImage(svg_image, crop_rect, options)) {
exception_state.ThrowDOMException(
......
......@@ -417,6 +417,8 @@ scoped_refptr<StaticBitmapImage> ScaleImage(
SkPixmap resized_pixmap(image_info, image_pixels->data(),
image_info.minRowBytes());
auto sk_image = image->PaintImageForCurrentFrame().GetSwSkImage();
if (!sk_image)
return nullptr;
sk_image->scalePixels(resized_pixmap,
SkSamplingOptions(parsed_options.resize_quality));
// Tag the resized Pixmap with the correct color space.
......
......@@ -83,6 +83,50 @@ testCases = [
});
}
},
{
description: 'createImageBitmap with <sourceType> source and ' +
'a value of 0 int resizeWidth',
promiseTestFunction:
(source, t) => {
return createImageBitmap(source, {resizeWidth:0, resizeHeight:10})
.catch(e => {
assert_throws_dom("InvalidStateError", () => { throw e });
});
}
},
{
description: 'createImageBitmap with <sourceType> source and ' +
'a value of 0 in resizeHeight',
promiseTestFunction:
(source, t) => {
return createImageBitmap(source, {resizeWidth:10, resizeHeight:0})
.catch(e => {
assert_throws_dom("InvalidStateError", () => { throw e });
});
}
},
{
description: 'createImageBitmap with <sourceType> source and ' +
'a value between 0 and 1 in resizeWidth',
promiseTestFunction:
(source, t) => {
return createImageBitmap(source, {resizeWidth:0.5, resizeHeight:10})
.catch(e => {
assert_throws_dom("InvalidStateError", () => { throw e });
});
}
},
{
description: 'createImageBitmap with <sourceType> source and ' +
'a value between 0 and 1 in resizeHeight',
promiseTestFunction:
(source, t) => {
return createImageBitmap(source, {resizeWidth:10, resizeHeight:0.5})
.catch(e => {
assert_throws_dom("InvalidStateError", () => { throw e });
});
}
},
];
// Generate the test matrix for each sourceType + testCase combo.
......
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