pdfviewer: more simple fixed to prevent crashes

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

git-svn-id: http://skia.googlecode.com/svn/trunk@10294 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
edisonn@google.com 2013-07-23 21:05:49 +00:00
parent b44334c1c0
commit 1f080163ac
3 changed files with 16 additions and 3 deletions

View File

@ -1949,6 +1949,10 @@ bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co
PdfContext pdfContext(fPdfDoc);
SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page, pdfContext.fTmpPageAllocator);
if (!tokenizer) {
// TODO(edisonn): report/warning/debug
return false;
}
pdfContext.fOriginalMatrix = SkMatrix::I();
pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page);

View File

@ -189,9 +189,9 @@ long SkNativeParsedPDF::readTrailer(const unsigned char* trailerStart, const uns
// TODO(edisonn): use null allocator, and let it just fail if memory
// needs allocated (but no crash)!
const unsigned char* current =
nextObject(0, trailerStart, trailerEnd, &trailerKeyword, fAllocator, NULL);
nextObject(0, trailerStart, trailerEnd, &trailerKeyword, NULL, NULL);
if (strlen("trailer") != trailerKeyword.len() &&
if (!trailerKeyword.isKeyword() || strlen("trailer") != trailerKeyword.len() ||
strncmp(trailerKeyword.c_str(), "trailer", strlen("trailer")) != 0) {
// TODO(edisonn): report warning, rebuild trailer from objects.
return -1;

View File

@ -125,6 +125,11 @@ static const unsigned char* endOfPdfToken(int level, const unsigned char* start,
// last elem has to be ]
static const unsigned char* readArray(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* array, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) {
if (allocator == NULL) {
// TODO(edisonn): report/warning error
return end;
}
TRACE_INDENT(level, "Array");
while (start < end) {
// skip white spaces
@ -208,7 +213,7 @@ static const unsigned char* readString(int level, const unsigned char* start, co
break;
case 'f':
*out = kFF_PdfWhiteSpace;
if (hasOut) { *out = kFF_PdfWhiteSpace; }
out++;
in += 2;
break;
@ -693,6 +698,10 @@ static const unsigned char* readInlineImageStream(int level, const unsigned char
}
static const unsigned char* readDictionary(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* dict, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) {
if (allocator == NULL) {
// TODO(edisonn): report/warning error
return end;
}
TRACE_INDENT(level, "Dictionary");
SkPdfObject::makeEmptyDictionary(dict);