Browse Source

LibWeb: Skip decoding favicon.ico if downloaded data is empty

Some sites don't have favicon.ico, so we may get 404 response.
In such cases, ResourceLoader still calls success_callback.
For favicon loading, we are not checking response headers or payload
size.
This will ultimately fail in Gfx::ImageDecoder::try_create().

So avoid unnecessary work by returning early, if data is empty.
Mandar Kulkarni 3 years ago
parent
commit
d787775806
1 changed files with 2 additions and 0 deletions
  1. 2 0
      Userland/Libraries/LibWeb/Loader/FrameLoader.cpp

+ 2 - 0
Userland/Libraries/LibWeb/Loader/FrameLoader.cpp

@@ -172,6 +172,8 @@ bool FrameLoader::load(LoadRequest& request, Type type)
             favicon_url,
             [this, favicon_url](auto data, auto&, auto) {
                 dbgln_if(SPAM_DEBUG, "Favicon downloaded, {} bytes from {}", data.size(), favicon_url);
+                if (data.is_empty())
+                    return;
                 RefPtr<Gfx::Bitmap> favicon_bitmap;
                 auto decoder = Gfx::ImageDecoder::try_create(data);
                 if (!decoder) {