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

Issue:
An invalid pdf is produced when there are many xref tables
Crate version: 0.34.0

When reading and saving a pdf with two xref tables, the tables are merged into one but /Prev is not removed from the trailer.

Use this code to replicate:
```
fn main() {
	let mut document = lopdf::Document::load("in.pdf").unwrap();
	document.save("out.pdf").unwrap();
}
```
Use [this](https://www.congress.gov/114/bills/sres199/BILLS-114sres199is.pdf) as `in.pdf`

`qpdf --check out.pdf` and `exiftool out.pdf` report the resulting file as malformed.



Discussion / hints:

Fix patch:
diff --git a/src/reader.rs b/src/reader.rs
index dc0dda7..5bdf910 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -231,7 +231,7 @@ impl<'a> Reader<'a> {
 
         // Read previous Xrefs of linearized or incremental updated document.
         let mut already_seen = HashSet::new();
-        let mut prev_xref_start = trailer.get(b"Prev").cloned();
+        let mut prev_xref_start = trailer.remove(b"Prev").ok_or(Error::DictKey);
         while let Ok(prev) = prev_xref_start.and_then(|offset| offset.as_i64()) {
             if already_seen.contains(&prev) {
                 break;


Test patch: