From e1c145b10afc593aedf2ea75dfb8bc6094fdf880 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 8 May 2021 22:05:40 -0400 Subject: [PATCH] Defer loading the Root, Info, and Encrypt objects until we have loaded all of the xref tables. --- pdfio-file.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pdfio-file.c b/pdfio-file.c index 2f50a05..d21510b 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -922,22 +922,25 @@ load_xref(pdfio_file_t *pdf, // I - PDF file // Save the trailer dictionary and grab the root (catalog) and info // objects... pdf->trailer = trailer.value.dict; - - if ((pdf->root = pdfioDictGetObject(pdf->trailer, "Root")) == NULL) - { - _pdfioFileError(pdf, "Missing Root object."); - return (false); - } - - pdf->info = pdfioDictGetObject(pdf->trailer, "Info"); - pdf->encrypt = pdfioDictGetObject(pdf->trailer, "Encrypt"); - pdf->id_array = pdfioDictGetArray(pdf->trailer, "ID"); } if ((xref_offset = (off_t)pdfioDictGetNumber(trailer.value.dict, "Prev")) <= 0) done = true; } + // Once we have all of the xref tables loaded, get the important objects and + // build the pages array... + if ((pdf->root = pdfioDictGetObject(pdf->trailer, "Root")) == NULL) + { + _pdfioFileError(pdf, "Missing Root object."); + return (false); + } + + pdf->info = pdfioDictGetObject(pdf->trailer, "Info"); + pdf->encrypt = pdfioDictGetObject(pdf->trailer, "Encrypt"); + pdf->id_array = pdfioDictGetArray(pdf->trailer, "ID"); + + // If we get this far, we successfully loaded everything... return (true); }