• Resolved Toengel

    (@toengel)


    Hi,

    i have the following warnings in my php logs:

    PHP Warning: Division by zero in /wp-content/plugins/amp/includes/sanitizers/class-amp-img-sanitizer.php on line 299

    How can I solve that?

    Toengel@Alex

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @toengel

    Thank you for the support topic, can you please send us your site data privately using AMP->Support option of the plugin and share UUID with us

    Docs : Support

    Thread Starter Toengel

    (@toengel)

    ampwp-2c37937f-1474-5871-856e-92cd1bf35954

    Plugin Support Milind More

    (@milindmore22)

    Hello @toengel

    Thank you for the info, but unfortunately we are unable to retrieve your PHP error log with data

    Can you please send us following:
    1) Page on which you are receiving notice
    2) Error with all the other details (full error)
    3) Anything suspicious in error log

    The code retrieve the image dimensions and adjust the image based on aspect ratio, somehow it divides height with 0 width which is cause of error.

    Additionally can you please check if you are using any broken image/ corrupted image on the page where you are seeing that image, which leads to failure in downloading

    Thread Starter Toengel

    (@toengel)

    Hi,

    I just found this line multiple times in my logs. No more information.

    I cannot tell you, when this issue occurs exactly.

    Toengel@Alex

    Plugin Support Milind More

    (@milindmore22)

    I will try to investigate if corrupted images or any particular image format may return zero for image dimensions

    Plugin Author Weston Ruter

    (@westonruter)

    This is the line in question: https://github.com/ampproject/amp-wp/blob/28bc1bb1ef7b4d78cdcce16d7c0ce114a1acec5e/includes/sanitizers/class-amp-img-sanitizer.php#L299

    // Let height have the right aspect ratio based on the width attribute.
    if ( is_numeric( $node->getAttribute( Attribute::WIDTH ) ) && isset( $dimensions['height'], $dimensions['width'] ) ) {
    	$height = ( (float) $node->getAttribute( Attribute::WIDTH ) * $dimensions['height'] ) / $dimensions['width'];
    }

    Somehow $dimensions['width'] is 0. Fixing the symptom would be to just make sure that $dimensions['width'] > 0. I wonder if it is actually false here and it is being cast to 0. I wonder if instead of checking isset() if we should rather be checking ! empty() in this method.

    The value for $dimensions['height'] is most likely coming from here: https://github.com/ampproject/amp-wp/blob/28bc1bb1ef7b4d78cdcce16d7c0ce114a1acec5e/includes/utils/class-amp-image-dimension-extractor.php#L246-L249

    So perhaps wp_getimagesize() is returning a bad value?

    Plugin Support Milind More

    (@milindmore22)

    @toengel

    I have opened a github issue to prevent warning, the fix will be likely to release in next version, please follow Github issue #6968 for further updates.

    I’ll mark this as resolved. Feel free to open a new support topic if you require any further assistance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PHP Warning: Division by zero in class-amp-img-sanitizer.php on line 299’ is closed to new replies.