Commit Diff


commit - ca863228bdda41111c7964d337736b9fc7a7d62f
commit + 6de503e15b1fd11418af24d8c6ade3348a315e8d
blob - 2d924ca91dadee7b855759132c77834944e7686d
blob + bac5a1f914864b7fb051c8409f67f5831da439fe
--- pdf.c
+++ pdf.c
@@ -4819,6 +4819,9 @@ parse_xrefs(struct Env *aux)
 	}
 	offset = H_INDEX_UINT(res->ast, 0);
 
+	// XXX put many checks here into semantic validations in the parser...
+	// e.g. offset bounds, /Prev type/value, loop detection
+
 	// verify the offset recovered is bounded to be in the file
 	if ( (offset <=0) || (offset >= aux->sz) ) {
 		log_message(5, "VIOLATION[5]: Invalid xref table offset = %ld. Valid range <0, %ld>\n",
blob - 215aef94226aa58f0554abc3d393ef02169ac62b (mode 644)
blob + /dev/null
--- test/invalid/loop.pdf
+++ /dev/null
@@ -1,121 +0,0 @@
-%PDF-1.7
-%Á∑·∂
-% vim: set tw=76 ts=2 et :
-% convert with:
-% ./fixlengths < hello.txt > hello.pdf ; ./genxref hello.pdf
-1 0 obj
-  <<  /Type /Catalog
-      /Outlines 6 0 R
-      /Pages 2 0 R
-  >>
-endobj
-
-2 0 obj
-  <<  /Type /Pages
-      /Kids [3 0 R]
-      /Count 1
-  >>
-endobj
-
-3 0 obj
-  <<  /Type /Page
-      /Parent 2 0 R
-      /MediaBox [0 0 595.276 841.89]
-      /Contents 4 0 R
-      /Resources <<
-        /ProcSet [/PDF /Text]
-        /Font << /F1 5 0 R >>
-        >>
-  >>
-endobj
-
-4 0 obj
-  <<  /Length 36  >>
-stream
-  BT 80 100 Td /F1 48 Tf (foo) Tj ET
-endstream
-endobj
-
-5 0 obj
-  <<  /Type /Font
-      /Subtype /Type1
-      /Name /F1
-      /BaseFont /Helvetica
-      /Encoding /MacRomanEncoding
-  >>
-endobj
-
-6 0 obj
-  <<  /Type /Outlines
-      /Count 0
-  >>
-endobj
-
-xref
-0 7
-0000000000 65535 f 
-0000000125 00000 n 
-0000000208 00000 n 
-0000000283 00000 n 
-0000000492 00000 n 
-0000000583 00000 n 
-0000000721 00000 n 
-
-trailer
-  <<  /Size 7
-      /Prev 1516
-      /Root 1 0 R
-  >>
-startxref
-779
-%%EOF
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-1 1 obj
-  <<  /Type /Catalog
-      /Outlines 6 0 R
-      /Pages 2 1 R
-  >>
-endobj
-
-2 1 obj
-  <<  /Type /Pages
-      /Kids [3 1 R]
-      /Count 1
-  >>
-endobj
-
-3 1 obj
-  <<  /Type /Page
-      /Parent 2 1 R
-      /MediaBox [0 0 595.276 841.89]
-      /Contents 4 1 R
-      /Resources <<
-        /ProcSet [/PDF /Text]
-        /Font << /F1 5 0 R >>
-        >>
-  >>
-endobj
-
-4 1 obj
-  <<  /Length 36  >>
-stream
-  BT 80 100 Td /F1 48 Tf (bar) Tj ET
-endstream
-endobj
-
-xref
-1 4
-0000001058 00001 n 
-0000001141 00001 n 
-0000001216 00001 n 
-0000001425 00001 n 
-
-trailer
-  <<  /Size 11
-      /Prev 779
-      /Root 1 1 R
-  >>
-startxref
-1516
-%%EOF
blob - /dev/null
blob + 215aef94226aa58f0554abc3d393ef02169ac62b (mode 644)
--- /dev/null
+++ test/invalid/loop.pdf.XXX
@@ -0,0 +1,121 @@
+%PDF-1.7
+%Á∑·∂
+% vim: set tw=76 ts=2 et :
+% convert with:
+% ./fixlengths < hello.txt > hello.pdf ; ./genxref hello.pdf
+1 0 obj
+  <<  /Type /Catalog
+      /Outlines 6 0 R
+      /Pages 2 0 R
+  >>
+endobj
+
+2 0 obj
+  <<  /Type /Pages
+      /Kids [3 0 R]
+      /Count 1
+  >>
+endobj
+
+3 0 obj
+  <<  /Type /Page
+      /Parent 2 0 R
+      /MediaBox [0 0 595.276 841.89]
+      /Contents 4 0 R
+      /Resources <<
+        /ProcSet [/PDF /Text]
+        /Font << /F1 5 0 R >>
+        >>
+  >>
+endobj
+
+4 0 obj
+  <<  /Length 36  >>
+stream
+  BT 80 100 Td /F1 48 Tf (foo) Tj ET
+endstream
+endobj
+
+5 0 obj
+  <<  /Type /Font
+      /Subtype /Type1
+      /Name /F1
+      /BaseFont /Helvetica
+      /Encoding /MacRomanEncoding
+  >>
+endobj
+
+6 0 obj
+  <<  /Type /Outlines
+      /Count 0
+  >>
+endobj
+
+xref
+0 7
+0000000000 65535 f 
+0000000125 00000 n 
+0000000208 00000 n 
+0000000283 00000 n 
+0000000492 00000 n 
+0000000583 00000 n 
+0000000721 00000 n 
+
+trailer
+  <<  /Size 7
+      /Prev 1516
+      /Root 1 0 R
+  >>
+startxref
+779
+%%EOF
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+1 1 obj
+  <<  /Type /Catalog
+      /Outlines 6 0 R
+      /Pages 2 1 R
+  >>
+endobj
+
+2 1 obj
+  <<  /Type /Pages
+      /Kids [3 1 R]
+      /Count 1
+  >>
+endobj
+
+3 1 obj
+  <<  /Type /Page
+      /Parent 2 1 R
+      /MediaBox [0 0 595.276 841.89]
+      /Contents 4 1 R
+      /Resources <<
+        /ProcSet [/PDF /Text]
+        /Font << /F1 5 0 R >>
+        >>
+  >>
+endobj
+
+4 1 obj
+  <<  /Length 36  >>
+stream
+  BT 80 100 Td /F1 48 Tf (bar) Tj ET
+endstream
+endobj
+
+xref
+1 4
+0000001058 00001 n 
+0000001141 00001 n 
+0000001216 00001 n 
+0000001425 00001 n 
+
+trailer
+  <<  /Size 11
+      /Prev 779
+      /Root 1 1 R
+  >>
+startxref
+1516
+%%EOF