Repository: J-F-Liu/lopdf (language: rust)

Issue:
Printable ASCII characters in binary comment produce error
`Document::save` fails if the binary comment contains printable ASCII characters.

To replicate:
```rust
const PDF: &[u8] = b"%PDF-1.0
%a\x80\x80\x80\x80
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
2 0 obj<</Type/Pages/Count 1/Kids[3 0 R]/MediaBox[0 0 595 842]>>endobj
3 0 obj<</Type/Page/Parent 2 0 R>>endobj
xref
0 4
0000000000 65535 f \n\
0000000016 00000 n \n\
0000000059 00000 n \n\
0000000130 00000 n \n\
trailer<</Root 1 0 R/Size 4>>
startxref
171
%%EOF";

fn main() {
    let mut document = lopdf::Document::load_from(std::io::Cursor::new(PDF)).unwrap();
    document.save("out.pdf").unwrap();
}
```


Discussion / hints:
Documents with a regular comment after the PDF header also result in this error:
```rust
const PDF: &[u8] = b"%PDF-1.0
% Just a regular comment
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
2 0 obj<</Type/Pages/Count 1/Kids[3 0 R]/MediaBox[0 0 595 842]>>endobj
3 0 obj<</Type/Page/Parent 2 0 R>>endobj
xref
0 4
0000000000 65535 f \n\
0000000034 00000 n \n\
0000000077 00000 n \n\
0000000148 00000 n \n\
trailer<</Root 1 0 R/Size 4>>
startxref
189
%%EOF";

fn main() {
	let mut document = lopdf::Document::load_from(std::io::Cursor::new(PDF)).unwrap();
	document.save("out.pdf").unwrap();
}
```

Fix patch:
diff --git a/src/reader.rs b/src/reader.rs
index 182c033..419303d 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -225,9 +225,13 @@ impl Reader<'_> {
 
         //The binary_mark is in line 2 after the pdf version. If at other line number, then will be declared as invalid pdf.
         if let Some(pos) = self.buffer.iter().position(|&byte| byte == b'\n') {
-            self.document.binary_mark =
+            if let Some(binary_mark) =
                 parser::binary_mark(ParserInput::new_extra(&self.buffer[pos + 1..], "binary_mark"))
-                    .unwrap_or(self.document.binary_mark);
+            {
+                if binary_mark.iter().all(|&byte| byte >= 128) {
+                    self.document.binary_mark = binary_mark;
+                }
+            }
         }
 
         let xref_start = Self::get_xref_start(self.buffer)?;


Test patch: