[Impeller] more nullchecks in image decoder. (flutter/engine#50787)

Speculative fix for https://github.com/flutter/flutter/issues/138897 which cannot be reprouced.
This commit is contained in:
Jonah Williams
2024-02-20 14:19:55 -08:00
committed by GitHub
parent 7c8dcec741
commit 3447737d89
2 changed files with 13 additions and 0 deletions

View File

@@ -556,6 +556,9 @@ std::shared_ptr<impeller::DeviceBuffer> 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<MallocDeviceBuffer>(descriptor)
: allocator_->CreateBuffer(descriptor);
if (!device_buffer) {
return false;
}
struct ImpellerPixelRef final : public SkPixelRef {
ImpellerPixelRef(int w, int h, void* s, size_t r)

View File

@@ -1050,6 +1050,13 @@ TEST_F(ImageDecoderFixtureTest,
PostTaskSync(runners.GetIOTaskRunner(), [&]() { io_manager.reset(); });
}
TEST_F(ImageDecoderFixtureTest, NullCheckBuffer) {
auto context = std::make_shared<impeller::TestImpellerContext>();
auto allocator = ImpellerAllocator(context->GetResourceAllocator());
EXPECT_FALSE(allocator.allocPixelRef(nullptr));
}
} // namespace testing
} // namespace flutter