aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer/pdfparser
diff options
context:
space:
mode:
authorGravatar edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-10 22:53:40 +0000
committerGravatar edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-10 22:53:40 +0000
commit432640ae0b9f4bc40e3447651ff5be0cd2be6b11 (patch)
tree3d65d767db64d24bc3b6e0b7fd37a6f6e38b2e5e /experimental/PdfViewer/pdfparser
parent2815c19c4d52f0fb522e21d1938d63e01c039124 (diff)
pdfviewer: don't crash when trailer is missing
Review URL: https://codereview.chromium.org/19027003 git-svn-id: http://skia.googlecode.com/svn/trunk@9987 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/PdfViewer/pdfparser')
-rw-r--r--experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp
index 5f16176376..9b668da498 100644
--- a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp
@@ -67,7 +67,10 @@ SkNativeParsedPDF* gDoc = NULL;
// 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,10 +100,16 @@ SkNativeParsedPDF::SkNativeParsedPDF(const char* path) : fAllocator(new SkPdfAll
// 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 @@ long SkNativeParsedPDF::readTrailer(unsigned char* trailerStart, unsigned char*
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);