Subject: bug#77196: tab-line-mode 's close-button show white rectangle when adjusting height via set-face-attribute

From: Cecilio Pardo <[email-masked]>
Date: Thu, 27 Mar 2025 13:35:41 +0100

> On 23/03/2025 7:41, Eli Zaretskii wrote:
>>> Environment
>>>
>>> Emacs 30.1 on Windows 10.
>>
>> I confirm the issue in Emacs 30.  But when I try this in Emacs 31,
>> Emacs crashes.  The backtrace is below.  Cecilio, could you please
>> look at this?

I can reproduce the original bug, but not the crash.  Anyway, it seems 
to happen because some glyph index is outside of the font range, so this 
patch should fix the crash.

From 5d1ea7c3dcdea9d0090071813cc732815c688f47 Mon Sep 17 00:00:00 2001
From: Cecilio Pardo <[email-masked]>
Date: Thu, 27 Mar 2025 13:26:00 +0100
Subject: [PATCH] ; w32: fail gracefully when using invalid glyphs on dwrite

* src/w32dwrite.c (text_extents_internal): Return false instead
of crashing with bad glyph indexes.
---
 src/w32dwrite.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/w32dwrite.c b/src/w32dwrite.c
index 4dc65b15db7..10af8545a11 100644
--- a/src/w32dwrite.c
+++ b/src/w32dwrite.c
@@ -610,6 +610,14 @@ text_extents_internal (IDWriteFontFace *dwrite_font_face,
 							       nglyphs,
 							       gmetrics,
 							       false);
+
+  /* E_INVALIDARG means some of the glyphs index is out of bounds for the font.  */
+  if (hr == E_INVALIDARG)
+    {
+      SAFE_FREE ();
+      return false;
+    }
+
   if (!verify_hr (hr, "Failed to GetGdiCompatibleGlyphMetrics"))
     {
       SAFE_FREE ();
-- 
2.35.1.windows.2