From b4fa8c5992d3ba02e8a15db03237443cb2251f13 Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Fri, 15 Nov 2024 08:38:18 +0000 Subject: [PATCH] PDFBOX-5901: avoid logging going mad git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921899 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fontbox/ttf/CmapSubtable.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java b/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java index 14b671f628c..e1c8dc74ec2 100644 --- a/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java +++ b/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java @@ -21,8 +21,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -516,6 +518,8 @@ void processSubtype2(TTFDataStream data, int numGlyphs) throws IOException LOG.warn("subtable has no glyphs"); return; } + Set logged = new HashSet<>(); + boolean maxLoggingReached = false; for (int i = 0; i <= maxSubHeaderIndex; ++i) { SubHeader sh = subHeaders[i]; @@ -547,8 +551,17 @@ void processSubtype2(TTFDataStream data, int numGlyphs) throws IOException if (p >= numGlyphs) { - LOG.warn("glyphId {} for charcode {} ignored, numGlyphs is {}", p, charCode, - numGlyphs); + if (!maxLoggingReached && !logged.contains(p)) + { + LOG.warn("glyphId {} for charcode {} ignored, numGlyphs is {}", p, charCode, + numGlyphs); + logged.add(p); + if (logged.size() > 10) + { + LOG.warn("too many bad glyphIds, more won't be reported for this table"); + maxLoggingReached = true; + } + } continue; }