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

Side by Side Diff: experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp

Issue 20004007: pdfviewer: don't crash if the xref is corrupted. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 #include "SkPdfNativeTokenizer.h" 2 #include "SkPdfNativeTokenizer.h"
3 #include "SkPdfObject.h" 3 #include "SkPdfObject.h"
4 #include "SkPdfConfig.h" 4 #include "SkPdfConfig.h"
5 5
6 #include "SkPdfStreamCommonDictionary_autogen.h" 6 #include "SkPdfStreamCommonDictionary_autogen.h"
7 #include "SkPdfImageDictionary_autogen.h" 7 #include "SkPdfImageDictionary_autogen.h"
8 8
9 // TODO(edisonn): perf!!! 9 // TODO(edisonn): perf!!!
10 // there could be 0s between start and end! but not in the needle. 10 // there could be 0s between start and end! but not in the needle.
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } else { 284 } else {
285 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 285 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
286 } 286 }
287 } 287 }
288 288
289 static int readStringLength(int level, const unsigned char* start, const unsigne d char* end) { 289 static int readStringLength(int level, const unsigned char* start, const unsigne d char* end) {
290 return readString(level, start, end, NULL) - start; 290 return readString(level, start, end, NULL) - start;
291 } 291 }
292 292
293 static const unsigned char* readString(int level, const unsigned char* start, co nst unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) { 293 static const unsigned char* readString(int level, const unsigned char* start, co nst unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
294 if (!allocator) {
295 return end;
296 }
294 int outLength = readStringLength(level, start, end); 297 int outLength = readStringLength(level, start, end);
295 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 298 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
296 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 299 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
297 start = readString(level, start, end, out); 300 start = readString(level, start, end, out);
298 SkPdfObject::makeString(out, out + outLength, str); 301 SkPdfObject::makeString(out, out + outLength, str);
299 TRACE_STRING(out, out + outLength); 302 TRACE_STRING(out, out + outLength);
300 return start; // consumed already ) at the end of the string 303 return start; // consumed already ) at the end of the string
301 } 304 }
302 305
303 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, unsigned char* out) { 306 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, unsigned char* out) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } else { 430 } else {
428 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 431 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
429 } 432 }
430 } 433 }
431 434
432 static int readHexStringLength(int level, const unsigned char* start, const unsi gned char* end) { 435 static int readHexStringLength(int level, const unsigned char* start, const unsi gned char* end) {
433 return readHexString(level, start, end, NULL) - start; 436 return readHexString(level, start, end, NULL) - start;
434 } 437 }
435 438
436 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) { 439 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
440 if (!allocator) {
441 return end;
442 }
437 int outLength = readHexStringLength(level, start, end); 443 int outLength = readHexStringLength(level, start, end);
438 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 444 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
439 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 445 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
440 start = readHexString(level, start, end, out); 446 start = readHexString(level, start, end, out);
441 SkPdfObject::makeHexString(out, out + outLength, str); 447 SkPdfObject::makeHexString(out, out + outLength, str);
442 TRACE_HEXSTRING(out, out + outLength); 448 TRACE_HEXSTRING(out, out + outLength);
443 return start; // consumed already > at the end of the string 449 return start; // consumed already > at the end of the string
444 } 450 }
445 451
446 // TODO(edisonn): before PDF 1.2 name could not have special characters, add ver sion parameter 452 // TODO(edisonn): before PDF 1.2 name could not have special characters, add ver sion parameter
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } else { 555 } else {
550 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 556 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
551 } 557 }
552 } 558 }
553 559
554 static int readNameLength(int level, const unsigned char* start, const unsigned char* end) { 560 static int readNameLength(int level, const unsigned char* start, const unsigned char* end) {
555 return readName(level, start, end, NULL) - start; 561 return readName(level, start, end, NULL) - start;
556 } 562 }
557 563
558 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, SkPdfObject* name, SkPdfAllocator* allocator) { 564 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, SkPdfObject* name, SkPdfAllocator* allocator) {
565 if (!allocator) {
566 return end;
567 }
559 int outLength = readNameLength(level, start, end); 568 int outLength = readNameLength(level, start, end);
560 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 569 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
561 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 570 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
562 start = readName(level, start, end, out); 571 start = readName(level, start, end, out);
563 SkPdfObject::makeName(out, out + outLength, name); 572 SkPdfObject::makeName(out, out + outLength, name);
564 TRACE_NAME(out, out + outLength); 573 TRACE_NAME(out, out + outLength);
565 return start; 574 return start;
566 } 575 }
567 576
568 // TODO(edisonn): pdf spec let Length to be an indirect object define after the stream 577 // TODO(edisonn): pdf spec let Length to be an indirect object define after the stream
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 SkPdfObject* obj = fAllocator->allocObject(); 1059 SkPdfObject* obj = fAllocator->allocObject();
1051 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc); 1060 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc);
1052 // TODO(edisonn): perf maybe we should not expand abreviation like t his 1061 // TODO(edisonn): perf maybe we should not expand abreviation like t his
1053 inlineImage->set(inlineImageKeyAbbreviationExpand(key), 1062 inlineImage->set(inlineImageKeyAbbreviationExpand(key),
1054 inlineImageValueAbbreviationExpand(obj)); 1063 inlineImageValueAbbreviationExpand(obj));
1055 } 1064 }
1056 } 1065 }
1057 // TODO(edisonn): report end of data with inline image without an EI 1066 // TODO(edisonn): report end of data with inline image without an EI
1058 return inlineImage; 1067 return inlineImage;
1059 } 1068 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698