From 79fcbe74ad4bf079e796631e62bb8525e3be3b4f Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Tue, 28 Feb 2023 15:09:41 +0000
Subject: [PATCH] avoid an assert in parse_fonts

This is an assertion of the type that catches an error (in user-supplied
data) that should be handled, namely the case where the /Font entry
of a dictionary is expected to be itself a dictionary but isn't.
The code already contains a path for the case where the /Font entry
is missing (return false) and I suppose the same, including the
TODO item "figure out how to handle", might as well apply instead
of the assertion.

Fixes #45.
---
 pdf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pdf.c b/pdf.c
index 5fea322..79c8853 100644
--- a/pdf.c
+++ b/pdf.c
@@ -3721,8 +3721,9 @@ bool parse_fonts(const HParsedToken *dict_t, RsrcDict_T *pgRsrc, struct Env *aux
 	// Handle a dictionary of font resources
 	item = dictentry(fontdict, "Font");
 	item = resolve(aux, item);
-	if (item) { // TODO: Failure ==> xref error -- Figure out how to handle
-		assert(item->token_type == TT_Dict);
+
+	if (item && item->token_type == TT_Dict) {
+		// XXX: Failure ==> xref error -- Figure out how to handle
 		processed = true;
 		Dict *fontlist = H_CAST(Dict, item);
 		if (pgRsrc->fonts) {
-- 
GitLab