diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php
index 6e2b5f1..f17a1f2 100644
--- a/wp-admin/includes/image.php
+++ b/wp-admin/includes/image.php
@@ -106,8 +106,14 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
        $metadata = array();
 
        if ( preg_match( '!^image/!', get_post_mime_type( $attachment_id ) ) ) {
-               $imagesize = getimagesize( $file );
-               $metadata['width']  = $imagesize[0];
-               $metadata['height'] = $imagesize[1];
+               // Skip dimension checks for SVG since they are vector-based.
+               $type = wp_check_filetype( $file );
+               if ( isset( $type['ext'] ) && $type['ext'] === 'svg' ) {
+                       $metadata['width']  = 0;
+                       $metadata['height'] = 0;
+               } else {
+                       $imagesize = @getimagesize( $file );
+                       if ( $imagesize ) {
+                               $metadata['width']  = $imagesize[0];
+                               $metadata['height'] = $imagesize[1];
+                       }
+               }
        }
 
        return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index 5d3f5f4..7f31a8c 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
@@ -691,6 +691,13 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
                $media_details['sizes'] = array();
        }
 
+       // Ensure SVGs don’t include invalid width/height in REST responses.
+       if ( isset( $response->data['mime_type'] ) && $response->data['mime_type'] === 'image/svg+xml' ) {
+               unset( $media_details['sizes'] );
+               unset( $media_details['height'] );
+               unset( $media_details['width'] );
+       }
+
        $response->data['media_details'] = $media_details;
 
        return $response;
