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

HTTP 500 error in combination with Gutenberg plugin when website logo is an SVG file with custom dimensions #18

Closed
fritteli opened this issue Dec 31, 2021 · 0 comments · Fixed by #23
Assignees
Labels
needs:engineering This requires engineering to resolve. type:bug Something isn't working.
Milestone

Comments

@fritteli
Copy link

fritteli commented Dec 31, 2021

Describe the bug

With activated Gutenberg plugin, when an SVG file is selected as the website logo AND the size of it is altered (effectively: once it is set to an explicit value) in the block's options, the website fails to load but only shows an HTTP 500 error instead.

Steps to Reproduce

  1. Use a block-theme (I guess any block theme; i could reproduce with twenty twenty-two).
  2. In the full page editor (Gutenberg), choose an SVG file as the website logo.
  3. Set a custom image width in the block options of the logo.
  4. Save the theme.
  5. Navigate to the website.
  6. An error message will appear.

Expected behavior

The page should display without error.

Screenshots

grafik

Environment information

  • Device: PC with Linux
  • OS: Gentoo Linux
  • Browser and version: Mozilla FIrefox 95.0.1 (64-bit)

WordPress information

Site Health info: ` ### wp-core ###

version: 5.9-beta4-52422
site_language: de_CH_informal
user_language: de_CH_informal
timezone: Europe/Berlin
permalink: /%year%/%monthnum%/%day%/%postname%/
https_status: false
multisite: false
user_registration: 0
blog_public: 0
default_comment_status: open
environment_type: production
user_count: 1
dotorg_communication: true

wp-paths-sizes

wordpress_path: /home/manuel/public_html/wordpress-beta
wordpress_size: 49.20 MB (51591651 bytes)
uploads_path: /home/manuel/public_html/wordpress-beta/wp-content/uploads
uploads_size: 50.72 kB (51937 bytes)
themes_path: /home/manuel/public_html/wordpress-beta/wp-content/themes
themes_size: 31.04 MB (32552997 bytes)
plugins_path: /home/manuel/public_html/wordpress-beta/wp-content/plugins
plugins_size: 18.80 MB (19713278 bytes)
database_size: 3.92 MB (4112384 bytes)
total_size: 103.02 MB (108022247 bytes)

wp-active-theme

name: Twenty Twenty-Two (twentytwentytwo)
version: 1.0
author: the WordPress team
author_website: https://wordpress.org/
parent_theme: none
theme_features: core-block-patterns, widgets-block-editor, post-thumbnails, responsive-embeds, editor-styles, html5, automatic-feed-links, block-templates, wp-block-styles, editor-style
theme_path: /home/manuel/public_html/wordpress-beta/wp-content/themes/twentytwentytwo
auto_update: Deaktiviert

wp-themes-inactive (12)

empowerment: version: 0.0.1-dev, author: Manuel Friedli, Automatische Aktualisierungen deaktiviert
Twenty Eleven: version: 3.9, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Fifteen: version: 3.0, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Fourteen: version: 3.2, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Nineteen: version: 2.1, author: WordPress-Team, Automatische Aktualisierungen deaktiviert
Twenty Seventeen: version: 2.8, author: dem WordPress-Team, Automatische Aktualisierungen deaktiviert
Twenty Sixteen: version: 2.5, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Ten: version: 3.5, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Thirteen: version: 3.4, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Twelve: version: 3.5, author: the WordPress team, Automatische Aktualisierungen deaktiviert
Twenty Twenty: version: 1.8, author: WordPress-Team, Automatische Aktualisierungen deaktiviert
Twenty Twenty-One: version: 1.4, author: the WordPress team, Automatische Aktualisierungen deaktiviert

wp-plugins-active (2)

Gutenberg: version: 12.2.0, author: Gutenberg Team, Automatische Aktualisierungen aktiviert
Safe SVG: version: 1.9.9, author: Daryll Doyle, Automatische Aktualisierungen aktiviert

wp-plugins-inactive (1)

Akismet Anti-Spam: version: 4.2.1, author: Automattic, Automatische Aktualisierungen aktiviert

wp-media

image_editor: WP_Image_Editor_GD
imagick_module_version: Nicht verfügbar
imagemagick_version: Nicht verfügbar
imagick_version: Nicht verfügbar
file_uploads: File uploads is turned off
post_max_size: 8M
upload_max_filesize: 2M
max_effective_size: 2 MB
max_file_uploads: 20
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, BMP
ghostscript_version: 9.55.0

wp-server

server_architecture: Linux 5.15.11-gentoo x86_64
httpd_software: Apache
php_version: 8.0.12 64bit
php_sapi: apache2handler
max_input_variables: 1000
time_limit: 30
memory_limit: 128M
admin_memory_limit: 256M
max_input_time: 60
upload_max_filesize: 2M
php_post_max_size: 8M
curl_version: 7.79.1 OpenSSL/1.1.1l
suhosin: false
imagick_availability: false
pretty_permalinks: true
htaccess_extra_rules: false

wp-database

extension: mysqli
server_version: 10.5.10-MariaDB-log
client_version: mysqlnd 8.0.12
max_allowed_packet: 16777216
max_connections: 151

wp-constants

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /home/manuel/public_html/wordpress-beta/wp-content
WP_PLUGIN_DIR: /home/manuel/public_html/wordpress-beta/wp-content/plugins
WP_MEMORY_LIMIT: 40M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: false
WP_DEBUG_DISPLAY: true
WP_DEBUG_LOG: false
SCRIPT_DEBUG: false
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: Nicht definiert
DB_CHARSET: utf8mb4
DB_COLLATE: undefined

wp-filesystem

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable

`

Additional context

PHP error log:
[Fri Dec 31 00:56:41.903692 2021] [php:error] [pid 4376] [client 127.0.0.1:48564] PHP Fatal error:  Uncaught DivisionByZeroError: Division by zero in /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/build/block-library/blocks/site-logo.php:20
Stack trace:
#0 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-hook.php(309): {closure}()
#1 /home/manuel/public_html/wordpress-beta/wp-includes/plugin.php(189): WP_Hook->apply_filters()
#2 /home/manuel/public_html/wordpress-beta/wp-includes/media.php(992): apply_filters()
#3 /home/manuel/public_html/wordpress-beta/wp-includes/media.php(1029): wp_get_attachment_image_src()
#4 /home/manuel/public_html/wordpress-beta/wp-includes/general-template.php(1093): wp_get_attachment_image()
#5 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/build/block-library/blocks/site-logo.php(26): get_custom_logo()
#6 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/lib/compat.php(132): gutenberg_render_block_core_site_logo()
#7 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(255): {closure}()
#8 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(241): WP_Block->render()
#9 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(241): WP_Block->render()
#10 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(241): WP_Block->render()
#11 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(883): WP_Block->render()
#12 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(921): render_block()
#13 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/build/block-library/blocks/template-part.php(132): do_blocks()
#14 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/lib/compat.php(132): gutenberg_render_block_core_template_part()
#15 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(255): {closure}()
#16 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(241): WP_Block->render()
#17 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(241): WP_Block->render()
#18 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(883): WP_Block->render()
#19 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(921): render_block()
#20 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/build/block-library/blocks/template-part.php(132): do_blocks()
#21 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/lib/compat.php(132): gutenberg_render_block_core_template_part()
#22 /home/manuel/public_html/wordpress-beta/wp-includes/class-wp-block.php(255): {closure}()
#23 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(883): WP_Block->render()
#24 /home/manuel/public_html/wordpress-beta/wp-includes/blocks.php(921): render_block()
#25 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/lib/compat/wordpress-5.9/block-template.php(217): do_blocks()
#26 /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/lib/compat/wordpress-5.9/template-canvas.php(12): gutenberg_get_the_template_html()
#27 /home/manuel/public_html/wordpress-beta/wp-includes/template-loader.php(106): include('...')
#28 /home/manuel/public_html/wordpress-beta/wp-blog-header.php(19): require_once('...')
#29 /home/manuel/public_html/wordpress-beta/index.php(17): require('...')
#30 {main}
  thrown in /home/manuel/public_html/wordpress-beta/wp-content/plugins/gutenberg/build/block-library/blocks/site-logo.php on line 20

The problem lies in the Gutenberg plugin, in the following code (gutenberg/build/block-library/blocks/site-logo.php, lines 15ff.):

function gutenberg_render_block_core_site_logo( $attributes ) {
        $adjust_width_height_filter = function ( $image ) use ( $attributes ) {
                if ( empty( $attributes['width'] ) || empty( $image ) ) {
                        return $image;
                }
                $height = (float) $attributes['width'] / ( (float) $image[1] / (float) $image[2] );
                return array( $image[0], (int) $attributes['width'], (int) $height );
        };

        add_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );

        $custom_logo = get_custom_logo();

        remove_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );

Apparently, $image[1] and $image[2] are both unset (or false), which results in a division by zero, but only if the width was manually altered (and therefore $attributes['width'] is not empty.

They get set to false by the Safe SVG plugin (safe-svg/safe-svg.php, lines 226ff.):

        /**
         * Filters the image src result.
         * Here we're gonna spoof the image size and set it to 100 width and height
         *
         * @param array|false $image Either array with src, width & height, icon src, or false.
         * @param int $attachment_id Image attachment ID.
         * @param string|array $size Size of image. Image size or array of width and height values
         *                                    (in that order). Default 'thumbnail'.
         * @param bool $icon Whether the image should be treated as an icon. Default false.
         *
         * @return array
         */
        public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
            if ( get_post_mime_type( $attachment_id ) == 'image/svg+xml' ) {
                $image['1'] = false;
                $image['2'] = false;
            }

            return $image;
        }

A trivial fix would be to set $image[1] and $image[2] to 100 instead of false, but I have no idea what (possibly negative) side effects that could cause.
I guess it also depends on the order in which the filters are registered (gutenberg-first vs. safe-svg-first).
Lastly, a fix could also be made in the Gutenberg plugin: only perform the calculation if $image[1] and $image[2] are both set to non-zero numerical values. But I assume it is very unusual for these values to be 0 in the first place, so I wouldn't count on the Gutenberg developers to be overly enthusiastic about implementing such a fix in their plugin.

@fritteli fritteli changed the title HTTP 500 error in combination with Gutenberg plugin when website logo is an SVG file HTTP 500 error in combination with Gutenberg plugin when website logo is an SVG file with custom dimensions Dec 31, 2021
@jeffpaul jeffpaul added needs:engineering This requires engineering to resolve. type:bug Something isn't working. labels Jan 4, 2022
@jeffpaul jeffpaul added this to the Future Release milestone Jan 4, 2022
@jeffpaul jeffpaul moved this to Incoming in Open Source Practice Jan 4, 2022
@jeffpaul jeffpaul moved this from Incoming to In Review in Open Source Practice Jan 26, 2022
@jeffpaul jeffpaul modified the milestones: Future Release, 1.10.0 Jan 26, 2022
Repository owner moved this from In Review to Merged in Open Source Practice Feb 15, 2022
@jeffpaul jeffpaul moved this from Merged to Done/Released in Open Source Practice Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:engineering This requires engineering to resolve. type:bug Something isn't working.
Projects
Archived in project
3 participants