Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3339)

Unified Diff: experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp

Issue 19027003: pdfviewer: don't crash when trailer is missing (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp
===================================================================
--- experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp (revision 9983)
+++ experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp (working copy)
@@ -67,7 +67,10 @@
// 1) run on a lot of file
// 2) recoverable corupt file: remove endobj, endsteam, remove other keywords, use other white spaces, insert comments randomly, ...
// 3) irrecoverable corrupt file
-SkNativeParsedPDF::SkNativeParsedPDF(const char* path) : fAllocator(new SkPdfAllocator()) {
+SkNativeParsedPDF::SkNativeParsedPDF(const char* path)
+ : fAllocator(new SkPdfAllocator())
+ , fRootCatalogRef(NULL)
+ , fRootCatalog(NULL) {
gDoc = this;
FILE* file = fopen(path, "r");
fContentLength = getFileSize(path);
@@ -97,11 +100,17 @@
// TODO(edisonn): warn/error expect fObjects[fRefCatalogId].fGeneration == fRefCatalogGeneration
// TODO(edisonn): security, verify that SkPdfCatalogDictionary is indeed using mapper
// load catalog
- fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef);
- SkPdfPageTreeNodeDictionary* tree = fRootCatalog->Pages(this);
- fillPages(tree);
+ if (fRootCatalogRef) {
+ fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef);
+ SkPdfPageTreeNodeDictionary* tree = fRootCatalog->Pages(this);
+ fillPages(tree);
+ } else {
+ // TODO(edisonn): corrupted pdf, read it from beginning and rebuild (xref, trailer, or just reall all objects)
+ // 0 pages
+ }
+
// now actually read all objects if we want, or do it lazyly
// and resolve references?... or not ...
}
@@ -171,7 +180,13 @@
SkPdfObject token;
current = nextObject(current, trailerEnd, &token, fAllocator);
+ if (!token.isDictionary()) {
+ return -1;
+ }
SkPdfFileTrailerDictionary* trailer = (SkPdfFileTrailerDictionary*)&token;
+ if (!trailer->valid()) {
+ return -1;
+ }
if (storeCatalog) {
const SkPdfObject* ref = trailer->Root(NULL);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698