File poppler-CVE-2025-52886.patch of Package poppler.40037
From ac36affcc8486de38e8905a8d6547a3464ff46e5 Mon Sep 17 00:00:00 2001
From: Sune Vuorela <sune@vuorela.dk>
Date: Tue, 3 Jun 2025 00:35:19 +0200
Subject: [PATCH] Limit ammount of annots per document/page
---
poppler/Annot.cc | 4 ++++
poppler/Page.cc | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
Index: poppler-22.01.0/poppler/Annot.cc
===================================================================
--- poppler-22.01.0.orig/poppler/Annot.cc
+++ poppler-22.01.0/poppler/Annot.cc
@@ -1596,6 +1596,10 @@ void Annot::removeReferencedObjects()
void Annot::incRefCnt()
{
+ if (refCnt > 100000) {
+ error(errSyntaxError, -1, "Annotations likely malformed. Too many references. Stopping processing annots on page {0:d}", page);
+ return;
+ }
refCnt++;
}
Index: poppler-22.01.0/poppler/Page.cc
===================================================================
--- poppler-22.01.0.orig/poppler/Page.cc
+++ poppler-22.01.0/poppler/Page.cc
@@ -288,6 +288,22 @@ Page::Page(PDFDoc *docA, int numA, Objec
goto err2;
}
+ if (annotsObj.isArray() && annotsObj.arrayGetLength() > 10000) {
+ error(errSyntaxError, -1, "Page annotations object (page {0:d}) is likely malformed. Too big: ({1:d})", num, annotsObj.arrayGetLength());
+ goto err2;
+ }
+ if (annotsObj.isRef()) {
+ auto resolvedObj = getAnnotsObject();
+ if (resolvedObj.isArray() && resolvedObj.arrayGetLength() > 10000) {
+ error(errSyntaxError, -1, "Page annotations object (page {0:d}) is likely malformed. Too big: ({1:d})", num, resolvedObj.arrayGetLength());
+ goto err2;
+ }
+ if (!resolvedObj.isArray() && !resolvedObj.isNull()) {
+ error(errSyntaxError, -1, "Page annotations object (page {0:d}) is wrong type ({1:s})", num, resolvedObj.getTypeName());
+ goto err2;
+ }
+ }
+
// contents
contents = pageObj.dictLookupNF("Contents").copy();
if (!(contents.isRef() || contents.isArray() || contents.isNull())) {