Skip to content

Prevent crashes from svg rendering#3123

Merged
hecrj merged 2 commits intoiced-rs:masterfrom
hammerlink:master
Dec 1, 2025
Merged

Prevent crashes from svg rendering#3123
hecrj merged 2 commits intoiced-rs:masterfrom
hammerlink:master

Conversation

@hammerlink
Copy link
Contributor

When rendering certain SVGs, resvg::render can panic because resvg uses several assert! calls internally. This caused application crashes in Cosmic Desktop: pop-os/cosmic-epoch#2452

This patch wraps the render call in std::panic::catch_unwind. If resvg panics, the panic is caught and None is returned instead of crashing the app.

Example problematic SVG:

<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">                                                    
  <defs>                                                                                                             
    <filter id="specular" width="50" height="50">                                              
      <feSpecularLighting result="specular" lighting-color="white"                                                   
                          x="10" y="10" width="5" height="5">                                                        
        <fePointLight x="50" y="50" z="200"/>                                                                        
      </feSpecularLighting>                                                                                          
    </filter>                                                                                                        
  </defs>                                                                                                            
  <rect width="100" height="100" fill="blue" filter="url(#specular)"/>                                               
</svg>

@hecrj
Copy link
Member

hecrj commented Nov 30, 2025

Isn't this a resvg bug?

@hecrj hecrj changed the title fix: prevent crashes from SVG rendering Prevent crashes from svg rendering Dec 1, 2025
@hecrj hecrj added this to the 0.14 milestone Dec 1, 2025
@hecrj hecrj added bug Something isn't working rendering svg fix labels Dec 1, 2025
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Changed it so that we still try to render the half-way drawn image. This should avoid constant cache misses and make any issue apparent to the user.

@hecrj hecrj enabled auto-merge December 1, 2025 16:04
@hecrj hecrj merged commit b02db5e into iced-rs:master Dec 1, 2025
15 checks passed
@hammerlink
Copy link
Contributor Author

Isn't this a resvg bug?

Yeah, it is a resvg bug. I mainly pushed this because it’s causing random crashes on Cosmic Desktop right now, and the fix for this issue in resvg has been sitting open since August. The fix should come from resvg, but this at least stops apps from crashing. Thanks for merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix rendering svg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants