Skip to content

Commit ddfd6cd

Browse files
committed
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
1 parent a129f9f commit ddfd6cd

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/media.cls.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ private function _detect_dimensions( $src ) {
11461146
$pathinfo = Utility::is_internal_file( $src );
11471147
if ( $pathinfo ) {
11481148
$src = $pathinfo[0];
1149-
} elseif ( apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) {
1149+
} elseif ( Utility::is_internal_url( $src ) || apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) {
11501150
return false;
11511151
}
11521152

@@ -1156,7 +1156,7 @@ private function _detect_dimensions( $src ) {
11561156

11571157
try {
11581158
$sizes = getimagesize( $src );
1159-
} catch ( \Exception $e ) {
1159+
} catch ( \Throwable $e ) {
11601160
return false;
11611161
}
11621162

src/utility.cls.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,31 @@ public static function internal( $host ) {
779779
return false;
780780
}
781781

782+
/**
783+
* Check if a URL belongs to an internal site or CDN domain.
784+
*
785+
* @since 7.9
786+
*
787+
* @param string $url URL.
788+
* @return bool True if internal host or relative path.
789+
*/
790+
public static function is_internal_url( $url ) {
791+
if ( 'data:' === substr( $url, 0, 5 ) ) {
792+
return false;
793+
}
794+
795+
$url_parsed = wp_parse_url( $url );
796+
if ( empty( $url_parsed['host'] ) ) {
797+
return true;
798+
}
799+
800+
if ( self::internal( $url_parsed['host'] ) || CDN::internal( $url_parsed['host'] ) ) {
801+
return true;
802+
}
803+
804+
return false;
805+
}
806+
782807
/**
783808
* Check if a URL is an internal existing file and return its real path and size.
784809
*

0 commit comments

Comments
 (0)