diff --git a/lib/ui/painting/image_decoder_impeller.cc b/lib/ui/painting/image_decoder_impeller.cc index 3ef8a8de5339c..587960f2baf3c 100644 --- a/lib/ui/painting/image_decoder_impeller.cc +++ b/lib/ui/painting/image_decoder_impeller.cc @@ -556,6 +556,9 @@ std::shared_ptr ImpellerAllocator::GetDeviceBuffer() } bool ImpellerAllocator::allocPixelRef(SkBitmap* bitmap) { + if (!bitmap) { + return false; + } const SkImageInfo& info = bitmap->info(); if (kUnknown_SkColorType == info.colorType() || info.width() < 0 || info.height() < 0 || !info.validRowBytes(bitmap->rowBytes())) { @@ -571,6 +574,9 @@ bool ImpellerAllocator::allocPixelRef(SkBitmap* bitmap) { kShouldUseMallocDeviceBuffer ? std::make_shared(descriptor) : allocator_->CreateBuffer(descriptor); + if (!device_buffer) { + return false; + } struct ImpellerPixelRef final : public SkPixelRef { ImpellerPixelRef(int w, int h, void* s, size_t r) diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index 210cab29ee5cd..2504a95064b6e 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -1050,6 +1050,13 @@ TEST_F(ImageDecoderFixtureTest, PostTaskSync(runners.GetIOTaskRunner(), [&]() { io_manager.reset(); }); } +TEST_F(ImageDecoderFixtureTest, NullCheckBuffer) { + auto context = std::make_shared(); + auto allocator = ImpellerAllocator(context->GetResourceAllocator()); + + EXPECT_FALSE(allocator.allocPixelRef(nullptr)); +} + } // namespace testing } // namespace flutter