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

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

Issue 23033022: pdfviewer: when q start, and an operator is called, it should not be able to see operands before q.… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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/pdfparser/native/SkPdfNativeDoc.h ('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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPdfNativeDoc.h" 8 #include "SkPdfNativeDoc.h"
9 #include "SkPdfNativeTokenizer.h" 9 #include "SkPdfNativeTokenizer.h"
10 #include "SkPdfNativeObject.h" 10 #include "SkPdfNativeObject.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 void SkPdfNativeDoc::addCrossSectionInfo(int id, int generation, int offset, boo l isFreed) { 352 void SkPdfNativeDoc::addCrossSectionInfo(int id, int generation, int offset, boo l isFreed) {
353 // TODO(edisonn): security here 353 // TODO(edisonn): security here
354 while (fObjects.count() < id + 1) { 354 while (fObjects.count() < id + 1) {
355 reset(fObjects.append()); 355 reset(fObjects.append());
356 } 356 }
357 357
358 fObjects[id].fOffset = offset; 358 fObjects[id].fOffset = offset;
359 fObjects[id].fObj = NULL; 359 fObjects[id].fObj = NULL;
360 fObjects[id].fResolvedReference = NULL; 360 fObjects[id].fResolvedReference = NULL;
361 fObjects[id].fIsReferenceResolved = false;
361 } 362 }
362 363
363 SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/ ) { 364 SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/ ) {
364 long startOffset = fObjects[id].fOffset; 365 long startOffset = fObjects[id].fOffset;
365 //long endOffset = fObjects[id].fOffsetEnd; 366 //long endOffset = fObjects[id].fOffsetEnd;
366 // TODO(edisonn): use hinted endOffset 367 // TODO(edisonn): use hinted endOffset
367 // TODO(edisonn): current implementation will result in a lot of memory usag e 368 // TODO(edisonn): current implementation will result in a lot of memory usag e
368 // to decrease memory usage, we wither need to be smart and know where objec ts end, and we will 369 // to decrease memory usage, we wither need to be smart and know where objec ts end, and we will
369 // alocate only the chancks needed, or the tokenizer will not make copies, b ut then it needs to 370 // alocate only the chancks needed, or the tokenizer will not make copies, b ut then it needs to
370 // cache the results so it does not go twice on the same buffer 371 // cache the results so it does not go twice on the same buffer
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 int id = ref->referenceId(); 540 int id = ref->referenceId();
540 // TODO(edisonn): generation/updates not supported now 541 // TODO(edisonn): generation/updates not supported now
541 //int gen = ref->referenceGeneration(); 542 //int gen = ref->referenceGeneration();
542 543
543 // TODO(edisonn): verify id and gen expected 544 // TODO(edisonn): verify id and gen expected
544 if (id < 0 || id >= fObjects.count()) { 545 if (id < 0 || id >= fObjects.count()) {
545 // TODO(edisonn): report error/warning 546 // TODO(edisonn): report error/warning
546 return NULL; 547 return NULL;
547 } 548 }
548 549
549 if (fObjects[id].fResolvedReference != NULL) { 550 if (fObjects[id].fIsReferenceResolved) {
550 551
551 #ifdef PDF_TRACE 552 #ifdef PDF_TRACE
552 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id ].fResolvedReference->toString(0, ref->toString().size() + 13).c_str()); 553 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id ].fResolvedReference->toString(0, ref->toString().size() + 13).c_str());
553 #endif 554 #endif
554 555
556 // TODO(edisonn): for known good documents, assert here THAT THE REF ERENCE IS NOT null
555 return fObjects[id].fResolvedReference; 557 return fObjects[id].fResolvedReference;
556 } 558 }
557 559
560 // TODO(edisonn): there are pdfs in the crashing suite that cause a stac k overflow here unless we check for resolved reference on next line
561 // determine if the pdf is corrupted, or we have a bug here
562
563 // avoids recursive calls
564 fObjects[id].fIsReferenceResolved = true;
565
558 if (fObjects[id].fObj == NULL) { 566 if (fObjects[id].fObj == NULL) {
559 fObjects[id].fObj = readObject(id); 567 fObjects[id].fObj = readObject(id);
560 } 568 }
561 569
562 if (fObjects[id].fResolvedReference == NULL) { 570 if (fObjects[id].fResolvedReference == NULL) {
563 if (!fObjects[id].fObj->isReference()) { 571 if (!fObjects[id].fObj->isReference()) {
564 fObjects[id].fResolvedReference = fObjects[id].fObj; 572 fObjects[id].fResolvedReference = fObjects[id].fObj;
565 } else { 573 } else {
566 fObjects[id].fResolvedReference = resolveReference(fObjects[id]. fObj); 574 fObjects[id].fResolvedReference = resolveReference(fObjects[id]. fObj);
567 } 575 }
568 } 576 }
569 577
570 #ifdef PDF_TRACE 578 #ifdef PDF_TRACE
571 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id].fR esolvedReference->toString(0, ref->toString().size() + 13).c_str()); 579 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id].fR esolvedReference->toString(0, ref->toString().size() + 13).c_str());
572 #endif 580 #endif
573 return fObjects[id].fResolvedReference; 581 return fObjects[id].fResolvedReference;
574 } 582 }
575 583
576 // TODO(edisonn): fix the mess with const, probably we need to remove it pre tty much everywhere 584 // TODO(edisonn): fix the mess with const, probably we need to remove it pre tty much everywhere
577 return (SkPdfNativeObject*)ref; 585 return (SkPdfNativeObject*)ref;
578 } 586 }
579 587
580 size_t SkPdfNativeDoc::bytesUsed() const { 588 size_t SkPdfNativeDoc::bytesUsed() const {
581 return fAllocator->bytesUsed() + 589 return fAllocator->bytesUsed() +
582 fContentLength + 590 fContentLength +
583 fObjects.count() * sizeof(PublicObjectEntry) + 591 fObjects.count() * sizeof(PublicObjectEntry) +
584 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + 592 fPages.count() * sizeof(SkPdfPageObjectDictionary*) +
585 sizeof(*this); 593 sizeof(*this);
586 } 594 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698