From 8085e3eb2655ba412fd803a38c4e58d1dc3b3c3b Mon Sep 17 00:00:00 2001 From: rmg-x Date: Sat, 6 Jul 2024 14:27:25 -0500 Subject: [PATCH] LibWeb: Add response status check in `SharedImageRequest::fetch_image` If an image response status was not ok, we would still pass the received body data to ImageDecoder which is not correct. --- Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp index befdd0cca1..7715175b6c 100644 --- a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp +++ b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -94,10 +95,13 @@ void SharedImageRequest::fetch_image(JS::Realm& realm, JS::NonnullGCPtrbody()) - response->body()->fully_read(realm, process_body, process_body_error, JS::NonnullGCPtr { realm.global_object() }); - else + // Check for failed fetch response + if (!Fetch::Infrastructure::is_ok_status(response->status()) || !response->body()) { handle_failed_fetch(); + return; + } + + response->body()->fully_read(realm, process_body, process_body_error, JS::NonnullGCPtr { realm.global_object() }); }; m_state = State::Fetching;