mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user