zliuent / svg-ps-converters

Tools for Exporting into SVG Tiny Portable/Secure Format
MIT License
0 stars 0 forks source link

Windows10 app produced UTF-8 BOM output can cause trouble for some decoding tools #1

Open zliuent opened 3 years ago

zliuent commented 3 years ago

Came across two cases where using the tiny ps file generated by svgconvernter.exe caused problems: The first case was that a BIMI certificate failed to pass https://www.mailkit.com/resources/bimi-inspector. The second case was that the browser displayed some extra question marks when rendering the inline svg data (obtained by base64 encoding the svgconvernter.exe output file, then decoding it back to UTF-8).

This type of problem could be fixed by enhancing each of the decoding application. It can also be fixed by removing BOM from UTF-8 output file when executing svgconvernter.exe. The latter approach could potentially save many developers from troubleshooting and fixing the decoder. In fact, using of a BOM is neither required nor recommended for UTF-8 based on Section 2.6 of the Unicode standard.

This issue report is tracking the BOM removal from UTF-8 output file.

zliuent commented 3 years ago

Here are steps can be used to verify the presence of the BOM, reproduce the problem and verify the fix

See the BOM

  1. Download and save the attached green.txt file and rename it to green.svg, which is a very simple svg tiny file
  2. Run it through the original svg-converter-0.1.exe
  3. Print out the hex to view the added BOM by the tool. With Windows PowerShell, you can run Format-hex green.svg Format-hex green_tiny_ps.svg Or you can run the following in Linux hexdump -C green.svg hexdump -C green_tiny_ps.svg Comparing the two outputs, you can see the added UTF-8 BOM chars (EF BB BF) at the beginning of the green_tiny_ps.svg.

    Reproduce the issue

  4. Encode green_tiny_ps.svg into base64 in PowerShell or Linux [System.Convert]::ToBase64String([IO.File]::ReadAllBytes(".\green_tiny_ps.svg")), or cat green_tiny_ps.svg | base64 You should be able to get output: 77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxzdmcgdmVyc2lvbj0iMS4yIiBiYXNlUHJvZmlsZT0idGlueS1wcyIgdmlld0JveD0iMCAwIDMwIDMwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KICA8dGl0bGU+R3JlZW48L3RpdGxlPg0KICA8ZGVzYz5BIFNpbXBsZSBTVkcgdGlueSBmaWxlPC9kZXNjPg0KICA8cmVjdCB4PSIxNSIgeT0iMTUiIHdpZHRoPSIxNSIgaGVpZ2h0PSIxNSIgZmlsbD0iZ3JlZW4iIC8+DQo8L3N2Zz4=
  5. Decode the base64 into a html page using JavaScript, as shown in the attached green.html.txt
  6. Rename green.html.txt to green.html
  7. Open the html file in a browser and it would display the BOM as  Of course you can choose to remove the BOM either in base64 encoding/decoding or before rendering in browser. But we can also choose to remove BOM from the intial svg-converter.exe output

    Verify the fix

    Repeat the steps above with the patched exe.

ivikramsahu commented 3 years ago

This works! good explanation @zliuent