Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Limit SVG Pixmap size to avoid GPUI texture allocation errors (#56468)

Lillian Rosefbd911ed3e0f
diff --git a/crates/gpui/src/svg_renderer.rs b/crates/gpui/src/svg_renderer.rs
index 5abd3341d22..35124b15ef8 100644
--- a/crates/gpui/src/svg_renderer.rs
+++ b/crates/gpui/src/svg_renderer.rs
@@ -228,13 +228,30 @@ impl SvgRenderer {
}
fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, usvg::Error> {
+ // Cap the size of the rendered pixmap to avoid texture allocation panics
+ // Related issue: #56466
+ const MAX_SIZE: f32 = 8192.0;
+
let tree = usvg::Tree::from_data(bytes, &self.usvg_options)?;
let svg_size = tree.size();
- let scale = match size {
+ let mut scale = match size {
SvgSize::Size(size) => size.width.0 as f32 / svg_size.width(),
SvgSize::ScaleFactor(scale) => scale,
};
+ let width = svg_size.width() * scale;
+ if width > MAX_SIZE {
+ log::warn!("Attempted to render pixmap where width ({width}) > MAX_SIZE ({MAX_SIZE})");
+ scale *= MAX_SIZE / width;
+ }
+ let height = svg_size.height() * scale;
+ if height > MAX_SIZE {
+ log::warn!(
+ "Attempted to render pixmap where height ({height}) > MAX_SIZE ({MAX_SIZE})"
+ );
+ scale *= MAX_SIZE / height;
+ }
+
// Render the SVG to a pixmap with the specified width and height.
let mut pixmap = resvg::tiny_skia::Pixmap::new(
(svg_size.width() * scale) as u32,