Hi Werner,

The patches should be self-explanatory - includng another one for the 
deprecation warnings too.

I am wondering about whether having something like the below too, but now that 
the actual problem is properly addressed, I don't feel too strongly about 
having such a band aid.

Hin-Tak

@@ -350,6 +350,14 @@
     cairo_recording_surface_ink_extents( state->rec_surface, &x, &y,
                                          &width, &height );
 
+    if (( width > 10000 ) || ( height > 10000 )) /* arbitrary large numbers */
+    {
+      fprintf(stderr, "cairo_recording_surface_ink_extents returns very large 
%dx%d bitmap\n",
+              width, height);
+      return FT_Err_Out_Of_Memory;
+      goto CleanCairo;
+    }
+
     /* We store the bounding box's `x` and `y` values so that the render */
     /* hook can apply a translation to get a tight rendering.            */
     state->x = x;
From 317023c40389713d457c6a1750b478c328cc1ca3 Mon Sep 17 00:00:00 2001
From: Hin-Tak Leung <[email protected]>
Date: Wed, 24 May 2023 23:38:29 +0100
Subject: [PATCH 1/2] * src/rsvg-port.c: Fix deprecation warnings against
 librsvg 2.52+

* src/rsvg-port.c (rsvg_port_preset_slot):
    Use `rsvg_handle_render_document' instead of
    `rsvg_handle_render_cairo', and `rsvg_handle_render_layer'
    instead of `rsvg_handle_render_cairo_sub', as suggested
    by the warning, conditionally on newer librsvg 2.52+.

Signed-off-by: Hin-Tak Leung <[email protected]>
---
 src/rsvg-port.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/rsvg-port.c b/src/rsvg-port.c
index 1286258..d446861 100644
--- a/src/rsvg-port.c
+++ b/src/rsvg-port.c
@@ -306,7 +306,17 @@
     if ( start_glyph_id == end_glyph_id )
     {
       /* Render the whole document to the recording surface. */
+#if LIBRSVG_CHECK_VERSION(2,52,0)
+      RsvgRectangle viewport = {
+        .x = 0,
+        .y = 0,
+        .width = dimension_svg.width,
+        .height = dimension_svg.height,
+      };
+      ret = rsvg_handle_render_document( handle, rec_cr, &viewport, NULL );
+#else
       ret = rsvg_handle_render_cairo ( handle, rec_cr );
+#endif
       if ( ret == FALSE )
       {
         error = FT_Err_Invalid_SVG_Document;
@@ -320,7 +330,17 @@
 
       /* Render only the element with its ID equal to `glyph<ID>`. */
       sprintf( str + 6, "%u", slot->glyph_index );
+#if LIBRSVG_CHECK_VERSION(2,52,0)
+      RsvgRectangle viewport = {
+        .x = 0,
+        .y = 0,
+        .width = dimension_svg.width,
+        .height = dimension_svg.height,
+      };
+      ret = rsvg_handle_render_layer( handle, rec_cr, str, &viewport, NULL );
+#else
       ret = rsvg_handle_render_cairo_sub( handle, rec_cr, str );
+#endif
       if ( ret == FALSE )
       {
         error = FT_Err_Invalid_SVG_Document;
-- 
2.40.1

From e6ec3c2630997b271042fddc8fdcc4d124e4866a Mon Sep 17 00:00:00 2001
From: Hin-Tak Leung <[email protected]>
Date: Wed, 24 May 2023 23:48:57 +0100
Subject: [PATCH 2/2] * src/rsvg-port.c: Fix out-of-memory conditions with
 newer librsvg

* src/rsvg-port.c (rsvg_port_preset_slot):
    Adjust for change of behavior of `rsvg_handle_get_intrinsic_dimensions'
    in librsvg 2.53+.

    The compile-time macro `LIBRSVG_CHECK_VERSION` is not used,
    as it is possible to build against one version but run
    against another version.

Excerpts from `rsvg_handle_get_intrinsic_dimensions' section in `librsvg/rsvg.h':

```
 * Before librsvg 2.54.0, the `out_has_width` and `out_has_height` arguments would be set to true or false
 * depending on whether the SVG document actually had `width` and `height` attributes, respectively.
 *
 * However, since librsvg 2.54.0, `width` and `height` are now [geometry
 * properties](https://www.w3.org/TR/SVG2/geometry.html) per the SVG2 specification; they
 * are not plain attributes.  SVG2 made it so that the initial value of those properties
 * is `auto`, which is equivalent to specifing a value of `100%`.  In this sense, even SVG
 * documents which lack `width` or `height` attributes semantically have to make them
 * default to `100%`.  This is why since librsvg 2.54.0, `out_has_width` and
 * `out_has_heigth` are always returned as `TRUE`, since with SVG2 all documents *have* a
 * default width and height of `100%`.
 *
```

Signed-off-by: Hin-Tak Leung <[email protected]>
---
 src/rsvg-port.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/rsvg-port.c b/src/rsvg-port.c
index d446861..07f65ec 100644
--- a/src/rsvg-port.c
+++ b/src/rsvg-port.c
@@ -241,12 +241,27 @@
     {
       dimension_svg.width  = (int)out_width.length; /* XXX rounding? */
       dimension_svg.height = (int)out_height.length;
+
+      /*
+       * librsvg 2.53+ behavior, on svg doc without explicit width/height.
+       * See `rsvg_handle_get_intrinsic_dimensions' section in
+       * the "librsvg/rsvg.h" header.
+       */
+      if (((int)out_width.length == 1) && ((int)out_height.length == 1)) {
+        dimension_svg.width  = units_per_EM;
+        dimension_svg.height = units_per_EM;
+      }
     }
     else
     {
-      /* If neither `ViewBox` nor `width`/`height` are present, the */
-      /* `units_per_EM` in SVG coordinates must be the same as      */
-      /* `units_per_EM` of the TTF/CFF outlines.                    */
+      /*
+       * If neither `ViewBox` nor `width`/`height` are present, the
+       * `units_per_EM` in SVG coordinates must be the same as
+       * `units_per_EM` of the TTF/CFF outlines.
+       *
+       * librsvg up to 2.52 behavior, on svg doc without explicit
+       * width/height.
+       */
       dimension_svg.width  = units_per_EM;
       dimension_svg.height = units_per_EM;
     }
-- 
2.40.1

Reply via email to