processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

Invalid SVG markup breaks page edit form #1925

Open daun opened 4 months ago

daun commented 4 months ago

Short description of the issue

SVGs with invalid markup will throw an exception in the page edit form when trying to calculate their size.

Expected behavior

Invalid SVGs should gracefully fall back to 0x0px size, like invalid jpeg/png images do.

Actual behavior

An exception is thrown, making it impossible to delete the invalid image from the page.

Optional: Screenshots/Links that demonstrate the issue

This is the page edit form in debug mode. In production mode, it just shows "Server error".

Screenshot-2024-05-15-at-15 44 29

Optional: Suggestion for a possible fix

Check for the result of the simplexml parser when trying to read the width/height in Pageimage.php.

I've created a PR with a suggested fix for this.

Steps to reproduce the issue

  1. Upload an invalid svg file to an image field
    Example content of a file which triggered the problem sh: inkscape: command not found
  2. Save the page

Setup/Environment

mpsn commented 3 months ago

:+1: for this. The root issue seems to be a buggy imagick plugin.

This probably only ever happens to SVG without width/height attributes. On the first run, its still valid XML, but getImageInfoSVG doesnt find size attributes, so Imagick is used. Imagick overrides the file contents with sh: inkscape: command not found, which is no longer valid XML and subsequently causes a fatal error.

This happened with PHP 8.0.30 and Imagick 3.7.0, other PHP versions on the same server do not seem to suffer from the same problem.