processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

Invalid SVG markup breaks page edit form

Open daun opened this issue 1 year ago • 1 comments

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

  • ProcessWire version: latest (3.0.238)
  • PHP version: 8.1

daun avatar May 15 '24 13:05 daun

:+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.

mpsn avatar Jul 02 '24 10:07 mpsn

@daun, can we close this?

matjazpotocnik avatar Dec 14 '24 12:12 matjazpotocnik

@daun, can we close this?

Yeah, I think so :)

daun avatar Dec 14 '24 14:12 daun