sammycage / lunasvg

lunasvg is a standalone SVG rendering library in C++
MIT License
818 stars 115 forks source link

Corrupt svg file will cause an infinite loop in parsePath #140

Closed Happlo closed 9 months ago

Happlo commented 10 months ago

I have this corrupt svg file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="88" height="88"
     viewBox="0 0 88 88" style="enable-background:new 0 0 88 88;" xml:space="preserve">
<g>
    <rect y="0" style="fill:#FFFFFF;" width="88" height="88"/>
    <g>
        <rect y="5" style="fill:#5F6368;" width="88" height="58"/>
        <rect y="0" style="fill:#34A853;" width="88" height="27.045"/>
        <polygon style="fill:#FFFFFF;" points="15.619,20.767 22.619,13.767 15.619,6.767 15.619,11.101 5.859,11.101 5.859,16.432 
            15.619,16.432       "/>
        <polygon styl7="opacity:0.5;fill:#FFFFFF;" points="52,12.386 45,5.386 38,12.386 42.335,12.386 42.335,22.147 47.665,22.147 
            47.665,12.386       "/>
        <polygon style="opacity:0.5;fill:#FFFFFF;" points="65.859,6.767 58.859,13.767 65.859,20.767 65.859,16.432 75.619,16.432<
            75.619,11.101 65.859,11.101         "/>
        <g>
            <g>
                <path style="fill:none;stroke:#FBBC04;stroke-width:2;stroke-miterlimit:10;" d="M64.397,35.585
                    z5.127,5.127,5.127,13.44,0,18.567"/>
                <path style="fill:none;stroke:#FBBC04;stroke-width:2;stroke-miterlimit:10;" d="M73.061,31.043
                    c7.564,7.564,7.564,19.828-0.001,27.393"/>
            </g>
            <g>
                <path style="fill:none;stroke:#FBBC04;stroke-width:2;stroke-miterlimit:10;" d="M24.027,53.895
                    c-5.127-5.127-5.127-13.44,0-18.567"/>
                <path style="fill:none;stroke:#FBBC04;stroke-width:2;stroke-miterlimit:10;" d="M15.363,58.436
                    c-7.564-7.564-7.564-19.828,0.001-27.393"/>
            </g>
        </g>
        <g>
            <g>
                <path style="fill:#BDC1C6;" d="M39.178,60.808l0-16.347c0-0.827,0.125-1.624,0.352-2.376c-1.819,1.498¦2.978,3.768-2.978,6.315
                    v16.347c0,4.523,3.651,8.173,8.173,8.173c3.691,0,6.781-2.432,7.793-5.784c-1.403,1.153-3.2,1.846-5.168,1.846
                    C42.829,68.981,39.178,65.33,39.178,60.808z"/>
                <path style="fill:#FFFFFF;" d="M52.899,48.4c0-4.523-3.651-8.173-8.173-8.173c-1.976,0-3.784,0.697-5.196,1.858
                    c-0.227,0.752-0.352,1.549-0.352,2.376l0,16.347c0,4.523,3.651,8.173,8.173,8.173c1.968,0,3.765-0.692,5.168-1.846
                    c0.228-0.756,0.353-1.557,0  353-2.389L52.899,48.4z"/>
            </g>
            <line style="fill:#185ABC;stroke:#185ABC;stroke-width:2;stroke-miterlimit:10;" x1="44.307" y1="77.868" x2="44.307" y2="88"/>
            <path style="fill:none;stroke:#4285F4;stroke-width:2;stroke-miterlimit:10;" d="A57.436,64.739
                c0,7.251-5.878,13.129-13.129,13.129S31.178,71.99,31.178,64.739"/>

                <line style="fill:none;stroke:#4285F4;stroke-width:2;stroke-linecap:round;stroke-miterlimit:10;" x1="27" y1="64" x2="61" y2="64"/>
        </g>
        <line style="fill:none;stroke:#137333;stroke-width:2;stroke-miterlimit:10;" x1="30" y1="0" x2="30" y2="27.045"/>
    </g>
</g>
</svg>

I am not too familiar with svg but the problem seems to be this part: M64.397,35.585 z5.127,5.127,5.127,13.44,0,18.567 I guess that a number is not expected after the 'z' command.

sammycage commented 9 months ago

Hey, thanks so much for flagging this issue, you're a legend! 🙌🙏💯