From b3dda3fe558da73e9b929790be8eb74afad337c6 Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Thu, 30 Mar 2023 14:14:52 +0000
Subject: [PATCH] don't emulate VIOL in error messages

While it might seem like a good idea to "grade" errors by severity,
we are not *really* in any place to do so accurately. Our tasks are

 (a) to decide, internally, whether to print a message or silently
     ignore a malformation, and
 (b) to ultimately judge the file valid or invalid as a whole.

Note that the latter part, as stated before, is not the responsibility
of parse_xrefs().

Reinstate the input file name in these error messages. That information
is useful when running the program on multiple files from a script, as
we have been doing.

While we're at it, fix style (line lengths).
---
 pdf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pdf.c b/pdf.c
index c1652fb..04e077d 100644
--- a/pdf.c
+++ b/pdf.c
@@ -4374,8 +4374,8 @@ process_page_content(struct Env *aux)
 	// XXX validate the presence of this field elsewhere
 	tok = dictentry(trailer, "Size");
 	if (tok == NULL || tok->token_type != TT_SINT) {
-		log_message(5, "VIOLATION[5]: error parsing trailer section!"
-		    "Missing or malformed /Size field.\n");
+		log_message(5, "%s: missing or malformed /Size in trailer\n",
+		    aux->infile);
 		return;
 	}
 	Size = H_CAST_SINT(tok);
@@ -4968,7 +4968,7 @@ parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs)
 			break;
 	}
 	if (res == NULL) {
-		log_message(5, "VIOLATION[5]: startxref not found\n");
+		log_message(5, "%s: startxref not found\n", infile);
 		goto end;
 	}
 	offset = H_INDEX_UINT(res->ast, 0);
@@ -4979,8 +4979,8 @@ parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs)
 	// verify the offset recovered is bounded to be in the file
 	// XXX this check is already present below by virtue of h_seek()
 	if (offset > sz) {
-		log_message(5, "VIOLATION[5]: startxref at %zu (%#zx) points outside the file\n",
-				sz - i, sz - i);
+		log_message(5, "%s: startxref value at %zu (%#zx) points "
+		    "outside the file\n", sz - i, sz - i);
 		goto end;
 	}
 
@@ -4989,8 +4989,8 @@ parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs)
 		assert(offset <= sz);
 		res = h_parse(p_xref, input + offset, sz - offset);
 		if (res == NULL || res->ast == NULL || H_INDEX_TOKEN(res->ast, 0) == NULL) {
-			log_message(5, "VIOLATION[5]: error parsing xref section at "
-			    "position %zu (%#zx)\n", offset, offset);
+			log_message(5, "%s: error parsing xref section at "
+			    "position %zu (%#zx)\n", infile, offset, offset);
 			break;
 		}
 
-- 
GitLab