f964c7
From a3bab162b2ae616074c8877a04556932998aeacd Mon Sep 17 00:00:00 2001
f964c7
From: Werner Lemberg <wl@gnu.org>
f964c7
Date: Mon, 19 Oct 2020 23:45:28 +0200
f964c7
Subject: [PATCH] [sfnt] Fix heap buffer overflow (#59308).
f964c7
f964c7
This is CVE-2020-15999.
f964c7
f964c7
* src/sfnt/pngshim.c (Load_SBit_Png): Test bitmap size earlier.
f964c7
---
f964c7
 ChangeLog          |  8 ++++++++
f964c7
 src/sfnt/pngshim.c | 14 +++++++-------
f964c7
 2 files changed, 15 insertions(+), 7 deletions(-)
f964c7
f964c7
diff --git a/src/sfnt/pngshim.c b/src/sfnt/pngshim.c
f964c7
index 2e64e5846..f55016122 100644
f964c7
--- a/src/sfnt/pngshim.c
f964c7
+++ b/src/sfnt/pngshim.c
f964c7
@@ -332,6 +332,13 @@
f964c7
 
f964c7
     if ( populate_map_and_metrics )
f964c7
     {
f964c7
+      /* reject too large bitmaps similarly to the rasterizer */
f964c7
+      if ( imgHeight > 0x7FFF || imgWidth > 0x7FFF )
f964c7
+      {
f964c7
+        error = FT_THROW( Array_Too_Large );
f964c7
+        goto DestroyExit;
f964c7
+      }
f964c7
+
f964c7
       metrics->width  = (FT_UShort)imgWidth;
f964c7
       metrics->height = (FT_UShort)imgHeight;
f964c7
 
f964c7
@@ -340,13 +347,6 @@
f964c7
       map->pixel_mode = FT_PIXEL_MODE_BGRA;
f964c7
       map->pitch      = (int)( map->width * 4 );
f964c7
       map->num_grays  = 256;
f964c7
-
f964c7
-      /* reject too large bitmaps similarly to the rasterizer */
f964c7
-      if ( map->rows > 0x7FFF || map->width > 0x7FFF )
f964c7
-      {
f964c7
-        error = FT_THROW( Array_Too_Large );
f964c7
-        goto DestroyExit;
f964c7
-      }
f964c7
     }
f964c7
 
f964c7
     /* convert palette/gray image to rgb */
f964c7
-- 
f964c7
2.26.2
f964c7