ThumbnailImage: Fix a nullptr check that could cause a crash
ThumbnailImage::UncompressImage will lead a crash within
gfx::ImageSkia::CreateFrom1xBitmap, because gfx::JPEGCodec::Decode may
return nullptr, but ThumbnailImage::UncompressImage do not check it.
Bug: 1493915
Change-Id: Ic857b003a82e74d6170fa8e361033bed998bef80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4944757
Commit-Queue: Eshwar Stalin <estalin@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1213954}
diff --git a/AUTHORS b/AUTHORS
index a764248..3338966 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -617,6 +617,7 @@
Jianneng Zhong <muzuiget@gmail.com>
Jiawei Shao <jiawei.shao@intel.com>
Jiawei Chen <jiawei.chen@dolby.com>
+Jiawei Wang <hellojw513@gmail.com>
Jiaxun Wei <leuisken@gmail.com>
Jiaxun Yang <jiaxun.yang@flygoat.com>
Jidong Qin <qinjidong@qianxin.com>
diff --git a/chrome/browser/ui/thumbnails/thumbnail_image.cc b/chrome/browser/ui/thumbnails/thumbnail_image.cc
index f67684c..dd6a109 100644
--- a/chrome/browser/ui/thumbnails/thumbnail_image.cc
+++ b/chrome/browser/ui/thumbnails/thumbnail_image.cc
@@ -232,9 +232,13 @@
// static
gfx::ImageSkia ThumbnailImage::UncompressImage(
CompressedThumbnailData compressed) {
- gfx::ImageSkia result =
- gfx::ImageSkia::CreateFrom1xBitmap(*gfx::JPEGCodec::Decode(
- compressed->data.data(), compressed->data.size()));
+ gfx::ImageSkia result;
+ std::unique_ptr<SkBitmap> bitmap(
+ gfx::JPEGCodec::Decode(compressed->data.data(), compressed->data.size()));
+ if (bitmap.get()) {
+ result = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap);
+ }
+
result.MakeThreadSafe();
return result;
}