Update resvg to fix panic (#10393)

This bumps us up a *long* way on the resvg/usvg crate, to fix a panic

Release Notes:

- Fixed a panic when rendering certain malformed SVGs
This commit is contained in:
Conrad Irwin 2024-04-10 20:12:05 -06:00 committed by GitHub
parent 339b29ef17
commit 3b68665277
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 114 additions and 176 deletions

266
Cargo.lock generated
View file

@ -264,12 +264,6 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "arrayvec"
version = "0.7.4"
@ -2621,16 +2615,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c578f2b9abb4d5f3fbb12aba4008084d435dc6a8425c195cfe0b3594bfea0c25"
dependencies = [
"bitflags 2.4.2",
"fontdb 0.16.2",
"fontdb",
"libm",
"log",
"rangemap",
"rustc-hash",
"rustybuzz 0.12.1",
"rustybuzz",
"self_cell",
"swash",
"sys-locale",
"ttf-parser 0.20.0",
"ttf-parser",
"unicode-bidi",
"unicode-linebreak",
"unicode-script",
@ -3043,12 +3037,9 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
[[package]]
name = "data-url"
version = "0.1.1"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a30bfce702bcfa94e906ef82421f2c0e61c076ad76030c16ee5d2e9a32fe193"
dependencies = [
"matches",
]
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
[[package]]
name = "db"
@ -3707,6 +3698,15 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "fdeflate"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645"
dependencies = [
"simd-adler32",
]
[[package]]
name = "feature_flags"
version = "0.1.0"
@ -3826,9 +3826,9 @@ dependencies = [
[[package]]
name = "float-cmp"
version = "0.5.3"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75224bec9bfe1a65e2d34132933f2de7fe79900c96a0174307554244ece8150e"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
[[package]]
name = "float-ord"
@ -3890,18 +3890,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a595cb550439a117696039dfc69830492058211b771a2a165379f2a1a53d84d"
dependencies = [
"roxmltree 0.19.0",
]
[[package]]
name = "fontdb"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e58903f4f8d5b58c7d300908e4ebe5289c1bfdf5587964330f12023b8ff17fd1"
dependencies = [
"log",
"memmap2 0.2.3",
"ttf-parser 0.12.3",
"roxmltree",
]
[[package]]
@ -3915,7 +3904,7 @@ dependencies = [
"memmap2 0.9.4",
"slotmap",
"tinyvec",
"ttf-parser 0.20.0",
"ttf-parser",
]
[[package]]
@ -4504,7 +4493,6 @@ dependencies = [
"taffy",
"thiserror",
"time",
"tiny-skia",
"usvg",
"util",
"uuid",
@ -4918,7 +4906,7 @@ dependencies = [
"num-iter",
"num-rational 0.3.2",
"num-traits",
"png",
"png 0.16.8",
"scoped_threadpool",
"tiff",
]
@ -4936,6 +4924,12 @@ dependencies = [
"workspace",
]
[[package]]
name = "imagesize"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284"
[[package]]
name = "indexmap"
version = "1.9.3"
@ -5288,11 +5282,12 @@ dependencies = [
[[package]]
name = "kurbo"
version = "0.8.3"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a53776d271cfb873b17c618af0298445c88afc52837f3e948fa3fafd131f449"
checksum = "6e5aa9f0f96a938266bdb12928a67169e8d22c6a786fda8ed984b85e6ba93c3c"
dependencies = [
"arrayvec 0.7.4",
"arrayvec",
"smallvec",
]
[[package]]
@ -5793,12 +5788,6 @@ dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matches"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]]
name = "matchit"
version = "0.7.3"
@ -5847,15 +5836,6 @@ dependencies = [
"rustix 0.38.32",
]
[[package]]
name = "memmap2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4"
dependencies = [
"libc",
]
[[package]]
name = "memmap2"
version = "0.8.0"
@ -5953,6 +5933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
dependencies = [
"adler",
"simd-adler32",
]
[[package]]
@ -6882,9 +6863,9 @@ dependencies = [
[[package]]
name = "pico-args"
version = "0.4.2"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
[[package]]
name = "pin-project"
@ -7020,6 +7001,19 @@ dependencies = [
"miniz_oxide 0.3.7",
]
[[package]]
name = "png"
version = "0.17.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1"
dependencies = [
"bitflags 1.3.2",
"crc32fast",
"fdeflate",
"flate2",
"miniz_oxide 0.7.1",
]
[[package]]
name = "polling"
version = "2.8.0"
@ -7576,12 +7570,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "rctree"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be9e29cb19c8fe84169fcb07f8f11e66bc9e6e0280efd4715c54818296f8a4a8"
[[package]]
name = "read-fonts"
version = "0.15.3"
@ -7781,16 +7769,14 @@ dependencies = [
[[package]]
name = "resvg"
version = "0.14.1"
version = "0.41.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09697862c5c3f940cbaffef91969c62188b5c8ed385b0aef43a5ff01ddc8000f"
checksum = "c2327ced609dadeed3e9702fec3e6b2ddd208758a9268d13e06566c6101ba533"
dependencies = [
"jpeg-decoder",
"log",
"pico-args",
"png",
"rgb",
"svgfilters",
"svgtypes",
"tiny-skia",
"usvg",
]
@ -7921,7 +7907,7 @@ dependencies = [
name = "rope"
version = "0.1.0"
dependencies = [
"arrayvec 0.7.4",
"arrayvec",
"bromberg_sl2",
"criterion",
"gpui",
@ -7933,15 +7919,6 @@ dependencies = [
"util",
]
[[package]]
name = "roxmltree"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "921904a62e410e37e215c40381b7117f830d9d89ba60ab5236170541dd25646b"
dependencies = [
"xmlparser",
]
[[package]]
name = "roxmltree"
version = "0.19.0"
@ -8056,7 +8033,7 @@ version = "1.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c4216490d5a413bc6d10fa4742bd7d4955941d062c0ef873141d6b0e7b30fd"
dependencies = [
"arrayvec 0.7.4",
"arrayvec",
"borsh",
"bytes 1.5.0",
"num-traits",
@ -8176,22 +8153,6 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "rustybuzz"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab463a295d00f3692e0974a0bfd83c7a9bcd119e27e07c2beecdb1b44a09d10"
dependencies = [
"bitflags 1.3.2",
"bytemuck",
"smallvec",
"ttf-parser 0.9.0",
"unicode-bidi-mirroring",
"unicode-ccc",
"unicode-general-category",
"unicode-script",
]
[[package]]
name = "rustybuzz"
version = "0.12.1"
@ -8202,7 +8163,7 @@ dependencies = [
"bytemuck",
"libm",
"smallvec",
"ttf-parser 0.20.0",
"ttf-parser",
"unicode-bidi-mirroring",
"unicode-ccc",
"unicode-properties",
@ -8215,15 +8176,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "safe_arch"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ff3d6d9696af502cc3110dacce942840fb06ff4514cad92236ecc455f2ce05"
dependencies = [
"bytemuck",
]
[[package]]
name = "safemem"
version = "0.3.3"
@ -8774,6 +8726,12 @@ dependencies = [
"rand_core 0.6.4",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "simdutf8"
version = "0.1.4"
@ -8818,18 +8776,18 @@ dependencies = [
"termcolor",
]
[[package]]
name = "siphasher"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "siphasher"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
[[package]]
name = "slab"
version = "0.4.9"
@ -9315,6 +9273,15 @@ dependencies = [
"ui",
]
[[package]]
name = "strict-num"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
dependencies = [
"float-cmp",
]
[[package]]
name = "stringprep"
version = "0.1.4"
@ -9374,7 +9341,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
name = "sum_tree"
version = "0.1.0"
dependencies = [
"arrayvec 0.7.4",
"arrayvec",
"ctor",
"env_logger",
"log",
@ -9456,24 +9423,14 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2"
[[package]]
name = "svgfilters"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb0dce2fee79ac40c21dafba48565ff7a5fa275e23ffe9ce047a40c9574ba34e"
dependencies = [
"float-cmp",
"rgb",
]
[[package]]
name = "svgtypes"
version = "0.5.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c536faaff1a10837cfe373142583f6e27d81e96beba339147e77b67c9f260ff"
checksum = "d97ca9a891c9c70da8139ac9d8e8ea36a210fa21bb50eccd75d4a9561c83e87f"
dependencies = [
"float-cmp",
"siphasher 0.2.3",
"kurbo",
"siphasher 1.0.1",
]
[[package]]
@ -9583,7 +9540,7 @@ name = "taffy"
version = "0.3.11"
source = "git+https://github.com/DioxusLabs/taffy?rev=1876f72bee5e376023eaa518aa7b8a34c769bd1b#1876f72bee5e376023eaa518aa7b8a34c769bd1b"
dependencies = [
"arrayvec 0.7.4",
"arrayvec",
"grid",
"num-traits",
"slotmap",
@ -9939,16 +9896,28 @@ dependencies = [
[[package]]
name = "tiny-skia"
version = "0.5.1"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf81f2900d2e235220e6f31ec9f63ade6a7f59090c556d74fe949bb3b15e9fe"
checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
dependencies = [
"arrayref",
"arrayvec 0.5.2",
"arrayvec",
"bytemuck",
"cfg-if",
"png",
"safe_arch",
"log",
"png 0.17.13",
"tiny-skia-path",
]
[[package]]
name = "tiny-skia-path"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93"
dependencies = [
"arrayref",
"bytemuck",
"strict-num",
]
[[package]]
@ -10631,18 +10600,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]]
name = "ttf-parser"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62ddb402ac6c2af6f7a2844243887631c4e94b51585b229fcfddb43958cd55ca"
[[package]]
name = "ttf-parser"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ae2f58a822f08abdaf668897e96a5656fe72f5a9ce66422423e8849384872e6"
[[package]]
name = "ttf-parser"
version = "0.20.0"
@ -10759,12 +10716,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc2520efa644f8268dce4dcd3050eaa7fc044fca03961e9998ac7e2e92b77cf1"
[[package]]
name = "unicode-general-category"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f9af028e052a610d99e066b33304625dea9613170a2563314490a4e6ec5cf7f"
[[package]]
name = "unicode-ident"
version = "1.0.12"
@ -10804,12 +10755,6 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-vo"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94"
[[package]]
name = "unicode-width"
version = "0.1.11"
@ -10866,28 +10811,23 @@ checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
name = "usvg"
version = "0.14.1"
version = "0.41.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef8352f317d8f9a918ba5154797fb2a93e2730244041cf7d5be35148266adfa5"
checksum = "5c704361d822337cfc00387672c7b59eaa72a1f0744f62b2a68aa228a0c6927d"
dependencies = [
"base64 0.13.1",
"base64 0.22.0",
"data-url",
"flate2",
"fontdb 0.5.4",
"imagesize",
"kurbo",
"log",
"memmap2 0.2.3",
"pico-args",
"rctree",
"roxmltree 0.14.1",
"rustybuzz 0.3.0",
"roxmltree",
"simplecss",
"siphasher 0.2.3",
"siphasher 1.0.1",
"strict-num",
"svgtypes",
"ttf-parser 0.12.3",
"unicode-bidi",
"unicode-script",
"unicode-vo",
"tiny-skia-path",
"xmlwriter",
]

View file

@ -50,9 +50,8 @@ profiling.workspace = true
rand.workspace = true
raw-window-handle = "0.6"
refineable.workspace = true
resvg = "0.14"
tiny-skia = "0.5"
usvg = { version = "0.14", features = [] }
resvg = { version = "0.41.0", default-features = false }
usvg = { version = "0.41.0", default-features = false }
schemars.workspace = true
seahash = "4.1"
semantic_version.workspace = true

View file

@ -1,7 +1,7 @@
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
use anyhow::anyhow;
use resvg::tiny_skia::Pixmap;
use std::{hash::Hash, sync::Arc};
use tiny_skia::Pixmap;
#[derive(Clone, PartialEq, Hash, Eq)]
pub(crate) struct RenderSvgParams {
@ -46,25 +46,24 @@ impl SvgRenderer {
pub fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, usvg::Error> {
let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
let tree_size = tree.svg_node().size;
let size = match size {
SvgSize::Size(size) => size,
SvgSize::ScaleFactor(scale) => crate::size(
DevicePixels((tree_size.width() * scale as f64) as i32),
DevicePixels((tree_size.height() * scale as f64) as i32),
DevicePixels((tree.size().width() * scale) as i32),
DevicePixels((tree.size().height() * scale) as i32),
),
};
// Render the SVG to a pixmap with the specified width and height.
let mut pixmap = tiny_skia::Pixmap::new(size.width.into(), size.height.into()).unwrap();
let mut pixmap =
resvg::tiny_skia::Pixmap::new(size.width.into(), size.height.into()).unwrap();
resvg::render(
&tree,
usvg::FitTo::Width(size.width.into()),
pixmap.as_mut(),
let transform = tree.view_box().to_transform(
resvg::tiny_skia::Size::from_wh(size.width.0 as f32, size.height.0 as f32).unwrap(),
);
resvg::render(&tree, transform, &mut pixmap.as_mut());
Ok(pixmap)
}
}