Commit Diff


commit - 81dc4dbad250ff8e9433eea76c1cc15649a2f927
commit + 9883a543682945509e8b20b5e9444e1b52876a09
blob - 1761f1414ca65700c8f8cea42ddf9ed29f4e7fe2
blob + 112a0d53be2dafe5e3c0328ec987519d77a1616e
--- pdf.c
+++ pdf.c
@@ -4947,13 +4947,13 @@ dumpstream(FILE *f, const HParsedToken *obj)
  * Allocates and returns an array of HParsedTokens, each containing the result
  * of a successful 'p_xref' parse. Sets the output parameter 'nxrefs' to the
  * number of elements.
+ *
+ * A return value of NULL indicates an empty result.
  */
 // XXX review changes to this function. see git -L /^parse_xrefs/,/^}/:pdf.c'
-void
-parse_xrefs(struct Env *aux)
+const HParsedToken **
+parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs)
 {
-	const uint8_t *input = aux->input;
-	size_t         sz    = aux->sz;
 	HParseResult *res = NULL;
 	const HParsedToken **xrefs = NULL;	/* empty result */
 	const HParsedToken *tok = NULL;
@@ -4978,9 +4978,9 @@ parse_xrefs(struct Env *aux)
 
 	// 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 <=0) || (offset >= aux->sz) ) {
+	if ( (offset <=0) || (offset >= sz) ) {
 		log_message(5, "VIOLATION[5]: Invalid xref table offset = %ld. Valid range <0, %ld>\n",
-				offset, aux->sz);
+				offset, sz);
 		goto end;
 	}
 
@@ -5037,8 +5037,8 @@ parse_xrefs(struct Env *aux)
 	}
 
 end:
-	aux->xrefs = xrefs;
-	aux->nxrefs = n;
+	*nxrefs = n;
+	return xrefs;
 }
 
 int
@@ -5139,7 +5139,7 @@ main(int argc, char *argv[])
 	init_LZW_parser();
 
 	/* parse all cross-reference sections and trailer dictionaries */
-	parse_xrefs(&aux);
+	aux.xrefs = parse_xrefs(input, sz, &aux.nxrefs);
 
 	/* run the main parser */
 	aux.stmparse = 1;			/* parse stream data? */