SVG uplaod with title comment of 3 characters fails; two characters work

Uploading an SVG that contains

<!-- Title: ABC Pages: 1 -->

fails with

Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?

Changing title to

<!-- Title: AB Pages: 1 -->

works. Yes, just changing ABC to AB made the difference.

It appears the length of the title name in the comment is limited to just two characters. Maybe something else but this is the case that reproduces the error every time.

i.e.

If a user sees the error message:

Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?

how is a user upon seeing the error message to know that one of the possible problems is that they should change the length of the title in the comment to two or less characters.

or another option is that

discourse should modify the security scanner/whistleblower to allow title comments of other lengths valid. :smiley:


The following SVG have line ends of LF and not CR/LF

Failing SVG

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
 -->
<!-- Title: ABC Pages: 1 -->
<svg width="110pt" height="64pt"
 viewBox="0.00 0.00 110.00 64.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 60)">
<title>Test</title>
<polygon fill="black" stroke="none" points="-4,4 -4,-60 106,-60 106,4 -4,4"/>
</g>
</svg>

Working SVG

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
 -->
<!-- Title: AB Pages: 1 -->
<svg width="110pt" height="64pt"
 viewBox="0.00 0.00 110.00 64.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 60)">
<title>Test</title>
<polygon fill="black" stroke="none" points="-4,4 -4,-60 106,-60 106,4 -4,4"/>
</g>
</svg>
1 Like

And if you add the extra character back it begins to fail again?

The are just xml comments, aren’t they? Is there any real impact in removing them?

Very strange… it seems to have something to do with the length of the comments?

If I remove any 1 character from a commented section it works (not just <!-- Title: ABC Pages: 1 --> but also the <!-- Generated by graphviz version 2.38.0 (20140413.2041) -->).

1 Like

Yes.

Taking a file that successfully uploads with 2 characters and adding the third character causes the upload to fail.

The reverse is also true.

Taking a file that fails to upload with 3 characters and removing the third character causes the upload to succeed.

1 Like

No there is technically no impact in removing them from the file.

However, the use-case in which these are being generated and used at a Discourse site is that

  1. We have Wiki post (Discourse post changed to Wiki so that any Basic user can edit them) used as Wiki pages (pages that are meant to be a source of common input and general knowledge; think Wikipedia). Thus one word with two different meanings here.

  2. I frequently generate content using Graphviz - DOT and export it to SVG for use with such Wiki pages.

While I can program with DOT, SVG, and HTML, some to many users are not as skilled. The site is for SWI-Prolog and some of the users are high school/college students just learning programming. While us advanced programmers would consider learning any of these as just learning another programming language and just get it done, the site is to help others learn Prolog. I can’t expect them to edit DOT, SVG, and much less HTML.

  1. The pages being Wiki pages for editing by and for everyone, expecting them to also figure out that once they create an SVG they have to convert the CR/LF to LF and then find and remove the offending comment line is a bit to much to ask. My goal is to get them to help create useful Wiki pages, not pull their hair out.

Anyway, the bug is now noted and ways to work around it for experienced programmers is demonstrated either by changing the text or removing the offending comment.

Thanks. :smiley:

PS

If the offending comment is a copyright, CC or other license, then that would be a problem. Also while I don’t know of or use any such add-on, add-ons sometimes extend languages by using specific patterns in comments as part of a language and removing them would be damaging.

1 Like

This is due to this code in the fastimage gem that we use

https://github.com/sdsykes/fastimage/blob/18831de7de75fb069b048aa9fcabc1f8b76efcad/lib/fastimage.rb#L506-L515

which looks for the “<svg” string in the first 250 characters of the file (which IMHO ought to be more than enough)

Would be great if graphviz would generate SVG files with less cruds…

6 Likes