This file is part of MXE. See LICENSE.md for licensing information. Contains ad hoc patches for cross building. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 28 Mar 2024 18:29:25 +0100 Subject: [PATCH 1/5] Ignore any errors from native-static-libs query It will not properly work with `-Zbuild-std`. diff --git a/meson.build b/meson.build index 1111111..2222222 100644 --- a/meson.build +++ b/meson.build @@ -353,13 +353,9 @@ if host_system in ['windows', 'linux'] native_libs = run_command( rustc_query_native_static_libs_args, capture: true, - check: true + check: false ) - if native_libs.stderr() != '' - error(native_libs.stderr()) - endif - foreach i: native_libs.stdout().split() if 'msvcrt' in i if i.endswith('.lib') # pre Rust 1.83 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 7 Jul 2023 18:41:29 +0200 Subject: [PATCH 2/5] Disable PDF/PostScript features in cairo-rs We build Cairo with `-Dzlib=disabled`, which implicitly disables these surface backends. diff --git a/librsvg-c/Cargo.toml b/librsvg-c/Cargo.toml index 1111111..2222222 100644 --- a/librsvg-c/Cargo.toml +++ b/librsvg-c/Cargo.toml @@ -10,7 +10,7 @@ edition.workspace = true rust-version.workspace = true [dependencies] -cairo-rs = { workspace = true, features = ["v1_16", "png", "pdf", "ps", "svg"] } +cairo-rs = { workspace = true, features = ["v1_16", "png", "svg"] } cast.workspace = true float-cmp.workspace = true gdk-pixbuf = { workspace = true, optional = true } diff --git a/rsvg/Cargo.toml b/rsvg/Cargo.toml index 1111111..2222222 100644 --- a/rsvg/Cargo.toml +++ b/rsvg/Cargo.toml @@ -48,7 +48,7 @@ name = "rsvg" [dependencies] # Keep these in sync with respect to the cairo-rs version: # src/lib.rs - toplevel example in the docs -cairo-rs = { workspace = true, features = ["v1_16", "png", "pdf", "ps", "svg"] } +cairo-rs = { workspace = true, features = ["v1_16", "png", "svg"] } cast.workspace = true cssparser.workspace = true cssparser-color.workspace = true From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 21 Apr 2024 12:01:02 +0200 Subject: [PATCH 3/5] Disallow GIF and WebP embedded in SVG images Upstream-Status: Inappropriate [disable feature] This is specific to libvips' prebuilt binaries. diff --git a/Cargo.lock b/Cargo.lock index 1111111..2222222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -453,12 +453,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - [[package]] name = "colorchoice" version = "1.0.5" @@ -980,16 +974,6 @@ dependencies = [ "rand_core 0.10.1", ] -[[package]] -name = "gif" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8cfcc411d9adbbaba82fb72661cc1bcca13e8bba98b364e62b2dba8f960159" -dependencies = [ - "color_quant", - "weezl 0.1.12", -] - [[package]] name = "gio" version = "0.22.9" @@ -1325,10 +1309,7 @@ checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" dependencies = [ "bytemuck", "byteorder-lite", - "color_quant", "dav1d", - "gif", - "image-webp", "moxcms", "mp4parse", "num-traits", @@ -1337,16 +1318,6 @@ dependencies = [ "zune-jpeg", ] -[[package]] -name = "image-webp" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3" -dependencies = [ - "byteorder-lite", - "quick-error 2.0.1", -] - [[package]] name = "indexmap" version = "2.14.2" @@ -1671,7 +1642,7 @@ dependencies = [ "stringprep", "thiserror", "time", - "weezl 0.2.1", + "weezl", ] [[package]] @@ -3184,12 +3155,6 @@ dependencies = [ "string_cache_codegen", ] -[[package]] -name = "weezl" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" - [[package]] name = "weezl" version = "0.2.1" diff --git a/rsvg/Cargo.toml b/rsvg/Cargo.toml index 1111111..2222222 100644 --- a/rsvg/Cargo.toml +++ b/rsvg/Cargo.toml @@ -57,7 +57,7 @@ encoding_rs.workspace = true float-cmp.workspace = true gio.workspace = true glib.workspace = true -image = { workspace = true, features = ["jpeg", "png", "gif", "webp"] } +image = { workspace = true, features = ["jpeg", "png"] } itertools.workspace = true language-tags.workspace = true libc.workspace = true From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 17 Apr 2026 12:47:45 +0200 Subject: [PATCH 4/5] Avoid linking with `--whole-archive` See: https://gitlab.gnome.org/GNOME/librsvg/-/issues/1210. diff --git a/rsvg/meson.build b/rsvg/meson.build index 1111111..2222222 100644 --- a/rsvg/meson.build +++ b/rsvg/meson.build @@ -234,7 +234,7 @@ if get_option('default_library') in ['shared', 'both'] librsvg_shared_lib = shared_library( 'rsvg-@0@'.format(librsvg_api_major), rsvg_dummy, - link_whole: librsvg_c_lib, + link_with: librsvg_c_lib, link_args: link_args, link_depends: librsvg_ver, dependencies: library_dependencies, @@ -352,7 +352,7 @@ if build_gir.allowed() librsvg_gir = shared_library( 'rsvg-gir', rsvg_dummy, - link_whole: librsvg_c_lib, + link_with: librsvg_c_lib, dependencies: library_dependencies, include_directories: [includeinc], ) From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 20 Sep 2026 11:11:58 +0200 Subject: [PATCH 5/5] Ensure embedded image memory limits are enforced The image crate limits per-image allocations to 512 MB by default. Since commit 87a2d8bb, librsvg has unconditionally disabled this limit. Only disable the image crate's limits when `unlimited_size` is enabled, and update the API and `rsvg-convert` documentation to reflect that `RSVG_HANDLE_FLAG_UNLIMITED` also applies to embedded images. Part-of: Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/librsvg/-/commit/9106011db93d701728ac2c9da50c9ab2c1bb5dc6] diff --git a/include/librsvg/rsvg.h b/include/librsvg/rsvg.h index 1111111..2222222 100644 --- a/include/librsvg/rsvg.h +++ b/include/librsvg/rsvg.h @@ -951,10 +951,11 @@ gboolean rsvg_handle_get_intrinsic_size_in_pixels (RsvgHandle *handle, /** * RsvgHandleFlags: * @RSVG_HANDLE_FLAGS_NONE: No flags are set. - * @RSVG_HANDLE_FLAG_UNLIMITED: Disable safety limits in the XML parser. Libxml2 has + * @RSVG_HANDLE_FLAG_UNLIMITED: Disable safety limits in the XML parser and on embedded images. Libxml2 has * [several limits](https://gitlab.gnome.org/GNOME/libxml2/blob/master/include/libxml/parserInternals.h) - * designed to keep malicious XML content from consuming too much memory while parsing. - * For security reasons, this should only be used for trusted input! Since: 2.40.3 + * designed to keep malicious XML content from consuming too much memory while parsing. The image crate + * also limits per-image allocations to 512 MB by default. For security reasons, this should only be used + * for trusted input! Since: 2.40.3 * @RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA: Use this if the Cairo surface to which you are * rendering is a PDF, PostScript, SVG, or Win32 Printing surface. This will make librsvg * and Cairo use the original, compressed data for images in the final output, instead of diff --git a/rsvg-convert.rst b/rsvg-convert.rst index 1111111..2222222 100644 --- a/rsvg-convert.rst +++ b/rsvg-convert.rst @@ -559,12 +559,12 @@ MISCELLANEOUS If not specified, all objects will be exported. ``-u``, ``--unlimited`` - Turn off the XML parser's guards. + Turn off safety limits in the XML parser and for embedded images. The XML parser has some guards designed to mitigate large CPU or - memory consumption in the face of malicious documents. It may also - refuse to resolve ``data:`` URIs used to embed image data in SVG - documents. If you are running into such issues when converting a - SVG, this option allows to turn off these guards. + memory consumption in the face of malicious documents. The image + crate also limits per-image allocations to 512 MB by default. If + you are running into such issues when converting a SVG, this option + allows to turn off these safety limits. ``--testing`` For developers only: render images for librsvg's test suite. diff --git a/rsvg/src/api.rs b/rsvg/src/api.rs index 1111111..2222222 100644 --- a/rsvg/src/api.rs +++ b/rsvg/src/api.rs @@ -124,7 +124,8 @@ impl Loader { /// Creates a `Loader` with the default flags. /// /// * [`unlimited_size`](#method.with_unlimited_size) defaults to `false`, as malicious - /// SVG documents could cause the XML parser to consume very large amounts of memory. + /// SVG documents could consume very large amounts of memory while parsing XML or + /// decoding embedded images. /// /// * [`keep_image_data`](#method.keep_image_data) defaults to /// `false`. You may only need this if rendering to Cairo diff --git a/rsvg/src/document.rs b/rsvg/src/document.rs index 1111111..2222222 100644 --- a/rsvg/src/document.rs +++ b/rsvg/src/document.rs @@ -78,7 +78,7 @@ pub struct LoadOptions { /// Load url resolver; all references will be resolved with respect to this. pub url_resolver: UrlResolver, - /// Whether to turn off size limits in libxml2. + /// Whether to turn off size limits in libxml2 and the image crate. pub unlimited_size: bool, /// Whether to keep original (undecoded) image data to embed in Cairo PDF surfaces. @@ -95,7 +95,7 @@ impl LoadOptions { } } - /// Sets whether libxml2's limits on memory usage should be turned off. + /// Sets whether libxml2's and the image crate's memory usage limits should be turned off. /// /// This should only be done for trusted data. pub fn with_unlimited_size(mut self, unlimited: bool) -> Self { @@ -881,7 +881,9 @@ fn load_image_with_image_rs( let cursor = Cursor::new(&bytes); let mut reader = image::ImageReader::with_format(cursor, format); - reader.no_limits(); + if load_options.unlimited_size { + reader.no_limits(); + } let image = reader .decode()