Skip to content

Commit 4aa3610

Browse files
fix: crash in clipboard.readImage() on malformed image data (#50491)
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. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Sam Attard <sattard@anthropic.com>
1 parent e1c17fd commit 4aa3610

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

shell/common/api/electron_api_clipboard.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ gfx::Image Clipboard::ReadImage(gin::Arguments* const args) {
248248
[](std::optional<gfx::Image>* image, base::RepeatingClosure cb,
249249
const std::vector<uint8_t>& result) {
250250
SkBitmap bitmap = gfx::PNGCodec::Decode(result);
251-
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
251+
if (bitmap.isNull()) {
252+
image->emplace();
253+
} else {
254+
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
255+
}
252256
std::move(cb).Run();
253257
},
254258
&image, std::move(callback)));

0 commit comments

Comments
 (0)