2a010a
From 53dfdcd8198d2b3201a23c4bad9190519ba918db Mon Sep 17 00:00:00 2001
2a010a
From: Werner Lemberg <wl@gnu.org>
2a010a
Date: Thu, 17 Mar 2022 19:24:16 +0100
2a010a
Subject: [PATCH] [sfnt] Avoid invalid face index.
2a010a
2a010a
Fixes #1138.
2a010a
2a010a
* src/sfnt/sfobjs.c (sfnt_init_face), src/sfnt/sfwoff2.c (woff2_open_font):
2a010a
Check `face_index` before decrementing.
2a010a
---
2a010a
 src/sfnt/sfobjs.c  | 2 +-
2a010a
 src/sfnt/sfwoff2.c | 2 +-
2a010a
 2 files changed, 2 insertions(+), 2 deletions(-)
2a010a
2a010a
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
2a010a
index f9d4d3858..9771c35df 100644
2a010a
--- a/src/sfnt/sfobjs.c
2a010a
+++ b/src/sfnt/sfobjs.c
2a010a
@@ -566,7 +566,7 @@
2a010a
     face_index = FT_ABS( face_instance_index ) & 0xFFFF;
2a010a
 
2a010a
     /* value -(N+1) requests information on index N */
2a010a
-    if ( face_instance_index < 0 )
2a010a
+    if ( face_instance_index < 0 && face_index > 0 )
2a010a
       face_index--;
2a010a
 
2a010a
     if ( face_index >= face->ttc_header.count )
2a010a
diff --git a/src/sfnt/sfwoff2.c b/src/sfnt/sfwoff2.c
2a010a
index cb1e0664a..165b875e5 100644
2a010a
--- a/src/sfnt/sfwoff2.c
2a010a
+++ b/src/sfnt/sfwoff2.c
2a010a
@@ -2085,7 +2085,7 @@
2a010a
     /* Validate requested face index. */
2a010a
     *num_faces = woff2.num_fonts;
2a010a
     /* value -(N+1) requests information on index N */
2a010a
-    if ( *face_instance_index < 0 )
2a010a
+    if ( *face_instance_index < 0 && face_index > 0 )
2a010a
       face_index--;
2a010a
 
2a010a
     if ( face_index >= woff2.num_fonts )
2a010a
-- 
2a010a
2.35.1
2a010a