Description: This patch fixes an infinite loop caused by CR instead of CRLF
 line endings in non-standard-conform pdf files.
Author: Robin Houston <robin@mysociety.org>
Bug-GitHub: https://github.com/robinhouston/pdftk/issues/1
 https://github.com/sebbacon/alaveteli/issues/305
Origin: https://github.com/robinhouston/pdftk/commit/05d6aeae83c305d5c7c7fab230722880399391a6


--- a/java/com/lowagie/text/pdf/PdfReader.java
+++ b/java/com/lowagie/text/pdf/PdfReader.java
@@ -1421,18 +1421,18 @@
 					// ssteward - 6/21/10
 					// stream should be followed by a LF or a CRLF, but not just a CR, per the PDF spec.
 					// however, I have encountered a generated PDF (Microsoft Reporting Services 10.0.0.0)
-					// that added a space after "stream" but before the CR; so gobble up unexpected chars
-					// until we find a LF
+					// that added a space after "stream" but before the CR; and also one (HP Digital
+                                        // Sending Device) that follows the stream with just a CR, so handle these cases too.
                     int ch = tokens.read();
-					/*
-                    if (ch != '\n')
+                    if (ch == ' ')
                         ch = tokens.read();
-                    if (ch != '\n')
-                        tokens.backOnePosition(ch);
-					*/
-					// ssteward
-					while (ch != '\n')
-						ch = tokens.read();
+                    if (ch == '\r') {
+                        ch = tokens.read();
+                        if (ch != '\n')
+                            tokens.backOnePosition(ch);
+                    }
+                    if (ch == -1)
+                        tokens.throwError("Unexpected end of file");
 
                     PRStream stream = new PRStream(this, tokens.getFilePointer());
                     stream.putAll(dic);
