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

Specific SVG causes SVGO to fail: TypeError: Cannot read properties of undefined (reading '0') Edit: Bug is worse than I thought, SVGO corrupts all SVGs before encountering the invalid SVG. #1974

Open
futuremotiondev opened this issue Apr 5, 2024 · 3 comments
Labels

Comments

@futuremotiondev
Copy link

futuremotiondev commented Apr 5, 2024

Describe the bug
SVGO is choking on a specific SVG file.

To Reproduce
Steps to reproduce the behavior:

  1. Download this SVG:
    Azure Media Player Audio Only B

Or paste this into a new text file and save with an SVG extension:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="-10 0 1034 1024">
   <path fill="currentColor"
d="M452 960q-73 0 -134.5 -36t-98 -98t-36.5 -135q0 -12 9 -21t21.5 -9t21 9t8.5 21q0 57 28.5 105t76.5 76t104.5 28t104.5 -28t76 -76t28 -105q0 -22 -6 -48q-2 -9 1 -17.5t11 -14.5q53 -37 83.5 -95t30.5 -123q0 -54 -20.5 -103t-58.5 -87t-87 -58.5t-103 -20.5v0
q-64 0 -120.5 28.5t-94.5 79.5t-49 114q-2 13 -12.5 20t-22.5 4.5t-19 -12.5t-5 -22q14 -78 60 -140t115 -97t148 -35v0q66 0 126 25t106.5 71.5t71.5 106.5t25 126q-1 74 -33.5 141t-90.5 114q4 22 4 43q0 73 -36 135t-98 98t-135 36zM333 721q-13 0 -21.5 -8.5t-8.5 -21.5
q0 -47 29 -87l36 -49l-32 -52q-33 -52 -33 -111q0 -56 28 -104t76 -76.5t105 -28.5q42 1 80 16.5t68 45.5t45.5 68t15.5 80q0 12 -8.5 21t-21.5 9v0q-12 0 -21 -9t-9 -21q0 -30 -11 -57.5t-32.5 -48.5t-48.5 -32.5t-57 -11.5q-40 0 -74.5 20t-54.5 54.5t-20 75.5t23 78
l43 69q5 8 5 17t-6 16l-48 66q-17 24 -17 52q0 13 -9 21.5t-21 8.5z" />
</svg>
  1. Run svgo '.\Azure Media Player Audio Only B.svg'
  2. See error:
TypeError: Cannot read properties of undefined (reading '0')
    at reflectPoint (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\plugins\convertPathData.js:1160:37)
    at C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\plugins\convertPathData.js:802:43
    at Array.filter (<anonymous>)
    at filters (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\plugins\convertPathData.js:397:15)
    at Object.enter (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\plugins\convertPathData.js:183:20)
    at visit (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\lib\xast.js:52:30)
    at visit (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\lib\xast.js:68:9)
    at visit (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\lib\xast.js:61:7)
    at invokePlugins (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\lib\svgo\plugins.js:25:7)
    at Object.fn (C:\Users\username\AppData\Roaming\nvm\v21.6.2\node_modules\svgo\lib\svgo\plugins.js:57:7)

Expected behavior
SVGO optimizes the SVG.

Or in the case of optimizing a folder, SVGO gracefully recovers from the error when processing a directory containing a bad SVG and continues processing other SVGs in the folder.

Desktop (please complete the following information):

  • SVGO Version 3.2.0
  • NodeJs Version 21.6.2
  • OS: Windows 10 Pro x64 22H2 (OS Build 19045.4239)

Additional context
None

@futuremotiondev futuremotiondev changed the title Specific SVG causes SVGO to fail: TypeError: Cannot read properties of undefined (reading '0') Specific SVG causes SVGO to fail: TypeError: Cannot read properties of undefined (reading '0') Edit: Bug is worse than I thought, SVGO corrupts all SVGs before encountering the invalid SVG. Apr 5, 2024
@futuremotiondev
Copy link
Author

Update to this issue. The severity is much higher than I thought.

I found another SVG causing SVGO to fail, but the terrible part is when I process a folder of SVGs that also contains the "bad" SVG using svgo -r -f 'C:\Icons\SomeFolderWithSVGs\', SVGO deletes all data from valid SVGs up until it reaches the "bad" SVG. So it's corrupting completely valid SVGs and causing data loss.

Here is a zip file of SVGs:

Microsoft Docons.zip

The "bad" SVG in this collection is brand-instagram-65369.svg

  1. Extract the zip somewhere, I.E. C:\Microsoft Docons\
  2. Open a terminal and enter svgo -r -f 'C:\Microsoft Docons\'
  3. You should see the same error I pasted in my first post.
  4. Open C:\Microsoft Docons\, and observe that these (valid) SVGs are now empty files:
.notdef-1114112.svg
arrow-down-65312.svg
arrow-down8-61614.svg
arrow-left-65313.svg
arrow-right-65305.svg
arrow-swap-65392.svg
arrow-up-left-65304.svg
arrow-up-right-61545.svg
arrow-up8-61613.svg
asterisk-59960.svg
asterisk-solid-62285.svg
backpack-65413.svg
blog-61995.svg
book-art64-61204.svg
book-open-65382.svg
book-solid-65365.svg
brand-dev-to-65368.svg
brand-facebook-65300.svg
brand-github-65302.svg

Definitely a pretty nasty bug. Having SVGO choke on a file is one thing, but corrupting other valid files is pretty awful.

Hopefully there is a resolution to this.

@KTibow
Copy link
Contributor

KTibow commented Apr 5, 2024

SVGO deletes all data from valid SVGs

I believe this is due to how Node handles the priority of events and stuff.

Cannot read properties of undefined (reading '0')

Duplicate of #1926, also see comments on #1927

@futuremotiondev
Copy link
Author

SVGO deletes all data from valid SVGs

I believe this is due to how Node handles the priority of events and stuff.

Can you elaborate on this? Is there any way to mitigate this behavior? I can't safely use SVGO in production if there is a chance that somewhere in the pipeline valid data gets wiped out.

Cannot read properties of undefined (reading '0')

Duplicate of #1926, also see comments on #1927

Read the comments, glad to hear a fix is in the works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants