[gs-commits] mupdf 1.16.1.41 Bug 701559 (1/2): Load Root/Version on th

[email protected] (Tor Andersson)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
commit 9b52ea86479bf8900fae5f1f92f42eaf177d9387
Author: Tor Andersson <[email protected]>
Date:   Tue Sep 10 15:55:29 2019 +0200

    Bug 701559 (1/2): Load Root/Version on the fly.
    
    Don't start loading objects before the user has had a chance to
    authenticate the document with a password. We'll end up filling
    the xref table with garbage objects.

diff --git a/include/mupdf/pdf/xref.h b/include/mupdf/pdf/xref.h
index 799d346..d9faaf0 100644
--- a/include/mupdf/pdf/xref.h
+++ b/include/mupdf/pdf/xref.h
@@ -75,6 +75,7 @@ fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int n
 fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *);
 fz_stream *pdf_open_contents_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
 
+int pdf_version(fz_context *ctx, pdf_document *doc);
 pdf_obj *pdf_trailer(fz_context *ctx, pdf_document *doc);
 void pdf_set_populating_xref_trailer(fz_context *ctx, pdf_document *doc, pdf_obj *trailer);
 int pdf_xref_len(fz_context *ctx, pdf_document *doc);
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 129b00f..2345a37 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -2357,7 +2357,8 @@ writeobjects(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int pass
 
 	if (!opts->do_incremental)
 	{
-		fz_write_printf(ctx, opts->out, "%%PDF-%d.%d\n", doc->version / 10, doc->version % 10);
+		int version = pdf_version(ctx, doc);
+		fz_write_printf(ctx, opts->out, "%%PDF-%d.%d\n", version / 10, version % 10);
 		fz_write_string(ctx, opts->out, "%\xC2\xB5\xC2\xB6\n\n");
 	}
 
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 8f88805..df79f18 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -588,6 +588,25 @@ void pdf_forget_xref(fz_context *ctx, pdf_document *doc)
  * magic version tag and startxref
  */
 
+int
+pdf_version(fz_context *ctx, pdf_document *doc)
+{
+	int version = doc->version;
+	fz_try(ctx)
+	{
+		pdf_obj *obj = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(Version), NULL);
+		const char *str = pdf_to_name(ctx, obj);
+		if (*str)
+			version = 10 * (fz_atof(str) + 0.05f);
+	}
+	fz_catch(ctx)
+	{
+		fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
+		fz_warn(ctx, "Ignoring broken Root/Version number.");
+	}
+	return version;
+}
+
 static void
 pdf_load_version(fz_context *ctx, pdf_document *doc)
 {
@@ -1473,20 +1492,6 @@ pdf_init_document(fz_context *ctx, pdf_document *doc)
 		fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
 		fz_warn(ctx, "Ignoring broken Optional Content configuration");
 	}
-
-	fz_try(ctx)
-	{
-		const char *version_str;
-		obj = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(Version), NULL);
-		version_str = pdf_to_name(ctx, obj);
-		if (*version_str)
-		{
-			int version = 10 * (fz_atof(version_str) + 0.05f);
-			if (version > doc->version)
-				doc->version = version;
-		}
-	}
-	fz_catch(ctx) { }
 }
 
 static void
@@ -2256,7 +2261,10 @@ int
 pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *buf, int size)
 {
 	if (!strcmp(key, "format"))
-		return (int)fz_snprintf(buf, size, "PDF %d.%d", doc->version/10, doc->version % 10);
+	{
+		int version = pdf_version(ctx, doc);
+		return (int)fz_snprintf(buf, size, "PDF %d.%d", version/10, version % 10);
+	}
 
 	if (!strcmp(key, "encryption"))
 	{
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c
index 819d68d..d52c877 100644
--- a/source/tools/pdfinfo.c
+++ b/source/tools/pdfinfo.c
@@ -182,8 +182,9 @@ showglobalinfo(fz_context *ctx, globals *glo)
 	pdf_obj *obj;
 	fz_output *out = glo->out;
 	pdf_document *doc = glo->doc;
+	int version = pdf_version(ctx, doc);
 
-	fz_write_printf(ctx, out, "\nPDF-%d.%d\n", doc->version / 10, doc->version % 10);
+	fz_write_printf(ctx, out, "\nPDF-%d.%d\n", version / 10, version % 10);
 
 	obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME(Info));
 	if (obj)

http://git.ghostscript.com/?p=mupdf.git;a=commit;h=9b52ea86479bf8900fae5f1f92f42eaf177d9387

--
MuPDF library
Artifex Software, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.