From 0cf7fc2ab88c5a727283efa31034a0bf6fac78b7 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Fri, 7 Aug 2026 23:06:43 +0600 Subject: [PATCH 1/2] fix(media): prevent getimagesize loopback deadlocks on missing images - Check if image URL host is internal domain in Utility::is_internal_url() - Return false early in _detect_dimensions() when local file is missing for internal URLs - Eliminate loopback HTTP GET requests to web server on missing images Fixes #894 --- src/media.cls.php | 4 ++-- src/utility.cls.php | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/media.cls.php b/src/media.cls.php index d124615cc..ef8765fa9 100644 --- a/src/media.cls.php +++ b/src/media.cls.php @@ -1146,7 +1146,7 @@ private function _detect_dimensions( $src ) { $pathinfo = Utility::is_internal_file( $src ); if ( $pathinfo ) { $src = $pathinfo[0]; - } elseif ( apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) { + } elseif ( Utility::is_internal_url( $src ) || apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) { return false; } @@ -1156,7 +1156,7 @@ private function _detect_dimensions( $src ) { try { $sizes = getimagesize( $src ); - } catch ( \Exception $e ) { + } catch ( \Throwable $e ) { return false; } diff --git a/src/utility.cls.php b/src/utility.cls.php index 46685edf0..0d84d6b9b 100644 --- a/src/utility.cls.php +++ b/src/utility.cls.php @@ -779,6 +779,31 @@ public static function internal( $host ) { return false; } + /** + * Check if a URL belongs to an internal site or CDN domain. + * + * @since 7.9 + * + * @param string $url URL. + * @return bool True if internal host or relative path. + */ + public static function is_internal_url( $url ) { + if ( 'data:' === substr( $url, 0, 5 ) ) { + return false; + } + + $url_parsed = wp_parse_url( $url ); + if ( empty( $url_parsed['host'] ) ) { + return true; + } + + if ( self::internal( $url_parsed['host'] ) || CDN::internal( $url_parsed['host'] ) ) { + return true; + } + + return false; + } + /** * Check if a URL is an internal existing file and return its real path and size. * From b80438cacde87f5a5a9ff1319d9bda63228cb299 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Tue, 11 Aug 2026 02:18:29 +0600 Subject: [PATCH 2/2] fix(media): reuse existing internal host check instead of new utility method - Remove public Utility::is_internal_url() added in this PR - Move host check into private Media::_is_internal_url() - Reuse Utility::internal() and CDN::internal() for host matching - Keep loopback deadlock prevention for missing internal images - Keep Throwable catch to handle PHP 8 ValueError on empty source Addresses PR review feedback. Refs #894 --- src/media.cls.php | 23 ++++++++++++++++++++++- src/utility.cls.php | 25 ------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/media.cls.php b/src/media.cls.php index ef8765fa9..10fdc12f6 100644 --- a/src/media.cls.php +++ b/src/media.cls.php @@ -1146,7 +1146,7 @@ private function _detect_dimensions( $src ) { $pathinfo = Utility::is_internal_file( $src ); if ( $pathinfo ) { $src = $pathinfo[0]; - } elseif ( Utility::is_internal_url( $src ) || apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) { + } elseif ( $this->_is_internal_url( $src ) || apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) { return false; } @@ -1167,6 +1167,27 @@ private function _detect_dimensions( $src ) { return false; } + /** + * Check if a URL belongs to an internal site or CDN domain. + * + * @since 7.9 + * + * @param string $url URL. + * @return bool True if internal host or relative path. + */ + private function _is_internal_url( $url ) { + if ( 'data:' === substr( $url, 0, 5 ) ) { + return false; + } + + $url_parsed = wp_parse_url( $url ); + if ( empty( $url_parsed['host'] ) ) { + return true; + } + + return Utility::internal( $url_parsed['host'] ) || CDN::internal( $url_parsed['host'] ); + } + /** * Parse iframe src. * diff --git a/src/utility.cls.php b/src/utility.cls.php index 0d84d6b9b..46685edf0 100644 --- a/src/utility.cls.php +++ b/src/utility.cls.php @@ -779,31 +779,6 @@ public static function internal( $host ) { return false; } - /** - * Check if a URL belongs to an internal site or CDN domain. - * - * @since 7.9 - * - * @param string $url URL. - * @return bool True if internal host or relative path. - */ - public static function is_internal_url( $url ) { - if ( 'data:' === substr( $url, 0, 5 ) ) { - return false; - } - - $url_parsed = wp_parse_url( $url ); - if ( empty( $url_parsed['host'] ) ) { - return true; - } - - if ( self::internal( $url_parsed['host'] ) || CDN::internal( $url_parsed['host'] ) ) { - return true; - } - - return false; - } - /** * Check if a URL is an internal existing file and return its real path and size. *