Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error (division by zero) in AMP_Core_Theme_Sanitizer::add_twentytwenty_custom_logo_fix() #7427

Closed
westonruter opened this issue Jan 25, 2023 · 2 comments · Fixed by #7429
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Milestone

Comments

@westonruter
Copy link
Member

Bug Description

See support topic.

This code is not accounting for the case where the site logo image for some reason has a height of zero:

$desktop_width = $desktop_height * ( $width / $height );
$mobile_width = $mobile_height * ( $width / $height );

This is also the case in this line:

$width = $height * ( $src[1] / $src[2] ); // Note that float values are allowed.

In both cases, we should make sure that when we cast the value to int that it is not zero, and if so, bail.

Expected Behaviour

No fatal error caused by division by zero should occur when site logo has an unexpected height of zero.

Screenshots

No response

PHP Version

No response

Plugin Version

2.3.0

AMP plugin template mode

Standard, Transitional

WordPress Version

No response

Site Health

No response

Gutenberg Version

No response

OS(s) Affected

No response

Browser(s) Affected

No response

Device(s) Affected

No response

Acceptance Criteria

No response

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

@milindmore22
Copy link
Collaborator

milindmore22 commented Jan 27, 2023

Just an Observation the user who reported this error is using an SVG image for logo

@pavanpatil1
Copy link

pavanpatil1 commented Feb 6, 2023

QA Passed ✅

Cross-checked the issue, Used the below snippet to verify the issue. The fix is working as expected.

if ( 'Twenty Twenty' === wp_get_theme()->get('Name') || 'Twenty Seventeen' === wp_get_theme()->get('Name') ) {
	add_filter(
		'get_custom_logo',
		static function () {
			return '<img src="https://avatars.githubusercontent.com/u/14114390?v=4" width="200" height="0">';
		}
	);
}

Before:

image

After fix:

image

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants