Commit 9f774202 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Stricter enforcement of image size

Decoding an image can result in it becoming a bitmap. To ensure this
doesn't negatively impact memory when decoding also apply the bitmap
size enforcement to already encoded images.

Bug: 1144768
Change-Id: I7fc36601e07fcafda65bc408f2563f0ec319dbf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547213Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828977}
parent 0b8f7f4c
...@@ -77,22 +77,21 @@ sk_sp<SkData> SerializeImage(SkImage* image, void* ctx) { ...@@ -77,22 +77,21 @@ sk_sp<SkData> SerializeImage(SkImage* image, void* ctx) {
ImageSerializationContext* context = ImageSerializationContext* context =
reinterpret_cast<ImageSerializationContext*>(ctx); reinterpret_cast<ImageSerializationContext*>(ctx);
// If there already exists encoded data and it is of a reasonable size use it const SkImageInfo& image_info = image->imageInfo();
// directly. // If decoding/encoding the image would result in it exceeding the allowable
// size, effectively delete it by providing no data.
if (context->max_representation_size != 0 &&
image_info.computeMinByteSize() > context->max_representation_size) {
return SkData::MakeEmpty();
}
// If there already exists encoded data use it directly.
sk_sp<SkData> encoded_data = image->refEncodedData(); sk_sp<SkData> encoded_data = image->refEncodedData();
if (!encoded_data) { if (!encoded_data) {
const SkImageInfo& image_info = image->imageInfo();
// If encoding the image will result in it exceeding the allowable size,
// effectively delete it by providing no data.
if (context->max_representation_size != 0 &&
image_info.computeMinByteSize() > context->max_representation_size) {
return SkData::MakeEmpty();
}
encoded_data = image->encodeToData(); encoded_data = image->encodeToData();
} }
// If encoding fails then no-op. // If encoding failed then no-op.
if (!encoded_data) if (!encoded_data)
return SkData::MakeEmpty(); return SkData::MakeEmpty();
......
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