fix: crash in clipboard.readImage() on malformed image data (#50475)

gfx::PNGCodec::Decode() returns a null SkBitmap when it fails to decode
the clipboard contents as a PNG. Passing that null bitmap to
gfx::Image::CreateFrom1xBitmap() triggers a crash.

Return an empty gfx::Image instead, matching the existing null-check
pattern in skia_util.cc.
This commit is contained in:
Samuel Attard
2026-03-25 13:47:00 -04:00
committed by GitHub
parent f6b43cb0ef
commit a48f03fb8d

View File

@@ -378,7 +378,11 @@ gfx::Image Clipboard::ReadImage(gin::Arguments* const args) {
[](std::optional<gfx::Image>* image, base::RepeatingClosure cb,
const std::vector<uint8_t>& result) {
SkBitmap bitmap = gfx::PNGCodec::Decode(result);
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
if (bitmap.isNull()) {
image->emplace();
} else {
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
}
std::move(cb).Run();
},
&image, std::move(callback)));