-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panic in setup_outline_page_ids() #263
Comments
Reposting the PDF in case the link goes dead: |
The panic happens because the PDF is malformed, cf. PDF 1.7, table 151 Destination syntax. Two of the contained In a sense, the panic is thus expected behavior. In the future, lopdf should probably handle similar errors more gracefully by returning in error instead of panicking, discussion on this probably should probably be held in #285. |
+1 I'm having the same problem. Some user provided PDFs don't contain a proper TOC structure (or in my case, the references to destinations are broken). The PDF in question is somehow broken in more than one way - and the problem should be fixed by using a proper PDF file - but still I'd like to be able to handle the error properly in my code and unwind my code properly and also display a proper error message. Right now it will just panic randomly when calling However, valid files work like a breeze, which is awesome. The offending code in toc.rs: fn setup_outline_page_ids<'a>(
outlines: &'a Vec<Outline>, result: &mut OutlinePageIds, level: usize,
) -> &'a Vec<Outline> {
for outline in outlines.iter() {
match outline {
Outline::Destination(destination) => {
// The following unwraps() should probably return an Err instead.
result.insert(
destination.title().unwrap().as_str().unwrap().to_vec(),
(destination.page().unwrap().as_reference().unwrap(), result.len(), level),
);
}
Outline::SubOutlines(sub_outlines) => {
setup_outline_page_ids(sub_outlines, result, level + 1);
}
}
}
outlines
} |
Calling get_toc() on the following pdf causes a panic in
setup_outline_page_ids
:https://www.etsi.org/deliver/etsi_ts/102000_102099/102034/01.02.01_60/ts_102034v010201p.pdf
Opening the file in evince shows that some chapters are missing pages (4 and 4.1) in the index view.
It looks like the second unwrap in the line fails and
destination.page().unwrap().as_reference()
returns an errorThe text was updated successfully, but these errors were encountered: