summaryrefslogtreecommitdiff
path: root/Resource
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-08-31 13:03:12 +0100
committerKen Sharp <ken.sharp@artifex.com>2022-08-31 13:03:12 +0100
commitf9343ada6c29dbdaac41863e79bae0055442b900 (patch)
treea2698c8074c7c48bb807c2ff40d6b0b6bd2f9e6f /Resource
parent4e91ed4d2d742aa46e0b5a05e6ee2c7f6e676e0e (diff)
downloadghostpdl-f9343ada6c29dbdaac41863e79bae0055442b900.tar.gz
GhostPDF + GS - small optimisation and avoid a circular reference
Bug #705834 "stack overflow in psi/idict.c:160 dict_alloc (exploitable)" This is caused by subsequent calls to .PDFInfo causing the Info dictionary to end up with circular references as we replace indirect references with PDF objects. I'd been meaning for some time to revisit the PostScript code and avoid calling .PDFInfo multiple times just for performance reasons (we have to convert the PDF dictionary to a PostScript dictionary every time). This commit uses the stored PostScript dictionary 'PDFInfo' instead of calling .PDFInfo which avoids the circular reference and is slightly more efficient.
Diffstat (limited to 'Resource')
-rw-r--r--Resource/Init/pdf_main.ps37
1 files changed, 22 insertions, 15 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index f5fcdd62f..23078a08f 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -807,31 +807,36 @@ currentdict /PDFSwitches undef
/newpdf_pagecount
{
- PDFFile //null eq not
+ currentdict /PDFInfo known
{
- PDFSTOPONERROR
- {
- PDFFile .PDFInfo //true
- }
- {
- PDFFile {.PDFInfo} stopped not
- } ifelse
-
+ PDFInfo
+ }
+ {
+ PDFFile //null eq not
{
- dup /NumPages known
+ PDFSTOPONERROR
{
- /NumPages get
+ PDFFile .PDFInfo //false
}
{
- pop 0
+ PDFFile {.PDFInfo} stopped
} ifelse
}
{
- pop 0
- } ifelse
+ //true
+ }ifelse
+
+ {
+ <</NumPages 0>>
+ } if
+ } ifelse
+
+ dup /NumPages known
+ {
+ /NumPages get
}
{
- 0
+ pop 0
} ifelse
}bind def
@@ -958,6 +963,7 @@ currentdict /PDFSwitches undef
pop
}ifelse
}ifelse
+ (Defined PDFInfo) == flush
} bind def
/newpdf_pdfgetpage
@@ -1073,6 +1079,7 @@ currentdict /PDFSwitches undef
<</NumPages 0>>
}
{
+(2) == flush
PDFFile {.PDFInfo} stopped
{
pop