admin管理员组

文章数量:1122846

In several sites (not all) after updating to wp 6.5, I have the following error:

Fatal error: Uncaught DivisionByZeroError: Division by zero in web/wp-includes/media.php:2134
Stack trace: #0 web/wp-includes/media.php(1894): wp_img_tag_add_width_and_height_attr('<img class="wp-...', 'template_part_f...', 267) #1 web/wp-includes/blocks/template-part.php(154): wp_filter_content_tags('\n<div class="wp...', 'template_part_f...') 
    #2 web/wp-includes/class-wp-block.php(463): render_block_core_template_part(Array, '', Object(WP_Block)) 
    #3 web/wp-includes/blocks.php(1705): WP_Block->render() 
    #4 web/wp-includes/blocks.php(1743): render_block(Array) 
    #5 web/wp-includes/block-template.php(260): do_blocks('<!-- wp:templat...') 
    #6 web/wp-includes/template-canvas.php(12): get_the_block_template_html() 
    #7 web/wp-includes/template-loader.php(106): include('/...') 
    #8 web/wp-blog-header.php(19): require_once('/...') #9 web/index.php(17): require('/...') 
    #10 {main} thrown in web/wp-includes/media.php on line 2134

I disabled all plugins,

I have activated the twenty-twentyfour default theme

I uploaded all 6.5 files (except wp-content) via FTP

I've cleaned up the db with wp-optimize

and the error persists...

[EDIT] It seems that the problem comes from the svg files that are added inline in the pages / articles. The width/height are stored at 0 (zero) in the database. And the process tries to create the "width" and "height" attributes by calculating them. But the calculation doesn't like division by zero. [/EDIT]

could you help me to debug this please?

In several sites (not all) after updating to wp 6.5, I have the following error:

Fatal error: Uncaught DivisionByZeroError: Division by zero in web/wp-includes/media.php:2134
Stack trace: #0 web/wp-includes/media.php(1894): wp_img_tag_add_width_and_height_attr('<img class="wp-...', 'template_part_f...', 267) #1 web/wp-includes/blocks/template-part.php(154): wp_filter_content_tags('\n<div class="wp...', 'template_part_f...') 
    #2 web/wp-includes/class-wp-block.php(463): render_block_core_template_part(Array, '', Object(WP_Block)) 
    #3 web/wp-includes/blocks.php(1705): WP_Block->render() 
    #4 web/wp-includes/blocks.php(1743): render_block(Array) 
    #5 web/wp-includes/block-template.php(260): do_blocks('<!-- wp:templat...') 
    #6 web/wp-includes/template-canvas.php(12): get_the_block_template_html() 
    #7 web/wp-includes/template-loader.php(106): include('/...') 
    #8 web/wp-blog-header.php(19): require_once('/...') #9 web/index.php(17): require('/...') 
    #10 {main} thrown in web/wp-includes/media.php on line 2134

I disabled all plugins,

I have activated the twenty-twentyfour default theme

I uploaded all 6.5 files (except wp-content) via FTP

I've cleaned up the db with wp-optimize

and the error persists...

[EDIT] It seems that the problem comes from the svg files that are added inline in the pages / articles. The width/height are stored at 0 (zero) in the database. And the process tries to create the "width" and "height" attributes by calculating them. But the calculation doesn't like division by zero. [/EDIT]

could you help me to debug this please?

Share Improve this question edited Apr 16, 2024 at 12:37 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Apr 16, 2024 at 6:34 micamica 1256 bronze badges 1
  • 2 This bug will be fixed in WP 6.6: core.trac.wordpress.org/ticket/61054 – cjbj Commented May 14, 2024 at 9:14
Add a comment  | 

1 Answer 1

Reset to default 2

If you dig into the function wp_img_tag_add_width_and_height_attr, you see the line where it goes wrong:

$size_array[1] = (int) round( $size_array[1] * $style_width / $size_array[0] ); 

Before this there are two places to do something. The first is a filter to bypass generating any widths and heights, which you could use like this:

add_filter ('wp_img_tag_add_width_and_height_attr', 'wpse424749_no_height_width');
  function wpse424749_no_height_width () {return false;}

However, this may not be what you want, if you just want to prevent svg images from having dimensions. This can be done in the second place, which is these lines:

$size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
if ( $size_array ) { ... here comes the lines where the division by 0 might occur

If you make sure no image dimensions are returned from the wp_image_src_get_dimensions whenever those dimensions are zero you will skip the lines where the division by zero happens. Like this:

add_filter ('wp_image_src_get_dimensions', 'wpse424749_skip_zero_width_height',10,4);
  function wpse424749_skip_zero_width_height ($dimensions, $image_src, $image_meta, $attachment_id) {
    if ($dimensions[0] == 0 || $dimensions[1] ==0 ) return false;
    else return ($dimensions);
  }

本文标签: Fatal error after update 65wpincludesmediaphp2134 svg inline sizes equal 0