pdfviewer: don't crash if the xref is corrupted.

Review URL: https://codereview.chromium.org/20004007

git-svn-id: http://skia.googlecode.com/svn/trunk@10293 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
edisonn@google.com 2013-07-23 20:47:05 +00:00
parent 70d75ca764
commit b44334c1c0
2 changed files with 10 additions and 1 deletions

View File

@ -197,7 +197,7 @@ SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fo
// TODO(edisonn): perf - make a map // TODO(edisonn): perf - make a map
for (unsigned int i = 0 ; i < doc->objects(); i++) { for (unsigned int i = 0 ; i < doc->objects(); i++) {
SkPdfObject* obj = doc->object(i); SkPdfObject* obj = doc->object(i);
if (!obj->isDictionary()) { if (!obj || !obj->isDictionary()) {
continue; continue;
} }

View File

@ -291,6 +291,9 @@ static int readStringLength(int level, const unsigned char* start, const unsigne
} }
static const unsigned char* readString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) { static const unsigned char* readString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
if (!allocator) {
return end;
}
int outLength = readStringLength(level, start, end); int outLength = readStringLength(level, start, end);
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer // TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
unsigned char* out = (unsigned char*)allocator->alloc(outLength); unsigned char* out = (unsigned char*)allocator->alloc(outLength);
@ -434,6 +437,9 @@ static int readHexStringLength(int level, const unsigned char* start, const unsi
} }
static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) { static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
if (!allocator) {
return end;
}
int outLength = readHexStringLength(level, start, end); int outLength = readHexStringLength(level, start, end);
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer // TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
unsigned char* out = (unsigned char*)allocator->alloc(outLength); unsigned char* out = (unsigned char*)allocator->alloc(outLength);
@ -556,6 +562,9 @@ static int readNameLength(int level, const unsigned char* start, const unsigned
} }
static const unsigned char* readName(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* name, SkPdfAllocator* allocator) { static const unsigned char* readName(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* name, SkPdfAllocator* allocator) {
if (!allocator) {
return end;
}
int outLength = readNameLength(level, start, end); int outLength = readNameLength(level, start, end);
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer // TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
unsigned char* out = (unsigned char*)allocator->alloc(outLength); unsigned char* out = (unsigned char*)allocator->alloc(outLength);