linebender / resvg

An SVG rendering library.
Apache License 2.0
2.84k stars 229 forks source link

Memory overflow #814

Closed Gaubee closed 2 months ago

Gaubee commented 2 months ago
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1"
    width="934.975830078125" height="1024" viewBox="0 0 934.975830078125 1024">
    <defs>
        <filter id="master_svga_90_04879" filterUnits="objectBoundingBox" color-interpolation-filters="sRGB" x="-120"
            y="-120" width="619.9678649902344" height="376.67909240722656">
            <feFlood flood-opacity="0" result="BackgroundImageFix" />
            <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape" />
            <feGaussianBlur stdDeviation="30" result="effect1_foregroundBlur" />
        </filter>
    </defs>
    <g>

        <g filter="url(#master_svga_90_04879)">
            <path
                d="M246.02157592773438,863.812059375L410.03657592773436,978.622359375L625.9895759277344,841.943359375L410.03657592773436,913.016459375L246.02157592773438,863.812059375Z"
                fill="#FEFFE1" fill-opacity="1" />
        </g>
    </g>
</svg>

just try this svg. version 0.42.0~0.43.0

RazrFalcon commented 2 months ago

Yes, this is an expected behavior. There are no memory usage limits in resvg. I assume you wanted to use filterUnits="userSpaceOnUse" instead of filterUnits="objectBoundingBox". Because right now your SVG requesting a 235567x51484px image.

Gaubee commented 2 months ago

Yes, this is an expected behavior. There are no memory usage limits in resvg. I assume you wanted to use filterUnits="userSpaceOnUse" instead of filterUnits="objectBoundingBox". Because right now your SVG requesting a 235567x51484px image.

Thank you for your response. I'm not an SVG expert; I'm just using resvg as the solution for rendering SVGs in my application. I'm currently using it as a dynamic link library to meet the SVG rendering needs in mobile. This leads to unbounded memory usage, causing the application to crash. Do you have any suggestions for this?

RazrFalcon commented 2 months ago

Currently, there are no plans on adding memory usage limits.

All you can do right now is too walk over nodes and check their bboxes. But if you're using resvg as a C library then there is no way to do so either. Or you can fork resvg and add necessary checks yourself.

I have added #815 to track this issue.