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

Side by Side Diff: src/core/SkTextBlob.cpp

Issue 1388543005: Validate text blob runs after SkTextBlob construction. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: now actually tested Created 5 years, 2 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
« no previous file with comments | « no previous file | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkTextBlob.h" 8 #include "SkTextBlob.h"
9 9
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 static const RunRecord* First(const SkTextBlob* blob) { 150 static const RunRecord* First(const SkTextBlob* blob) {
151 // The first record (if present) is stored following the blob object. 151 // The first record (if present) is stored following the blob object.
152 return reinterpret_cast<const RunRecord*>(blob + 1); 152 return reinterpret_cast<const RunRecord*>(blob + 1);
153 } 153 }
154 154
155 static const RunRecord* Next(const RunRecord* run) { 155 static const RunRecord* Next(const RunRecord* run) {
156 return reinterpret_cast<const RunRecord*>(reinterpret_cast<const uint8_t *>(run) 156 return reinterpret_cast<const RunRecord*>(reinterpret_cast<const uint8_t *>(run)
157 + StorageSize(run->glyphCount(), run->positioning())); 157 + StorageSize(run->glyphCount(), run->positioning()));
158 } 158 }
159 159
160 void validate(uint8_t* storageTop) const { 160 void validate(const uint8_t* storageTop) const {
161 SkASSERT(kRunRecordMagic == fMagic); 161 SkASSERT(kRunRecordMagic == fMagic);
162 SkASSERT((uint8_t*)Next(this) <= storageTop); 162 SkASSERT((uint8_t*)Next(this) <= storageTop);
163 SkASSERT(glyphBuffer() + fCount <= (uint16_t*)posBuffer()); 163 SkASSERT(glyphBuffer() + fCount <= (uint16_t*)posBuffer());
164 SkASSERT(posBuffer() + fCount * ScalarsPerGlyph(fPositioning) <= (SkScal ar*)Next(this)); 164 SkASSERT(posBuffer() + fCount * ScalarsPerGlyph(fPositioning) <= (SkScal ar*)Next(this));
165 } 165 }
166 166
167 private: 167 private:
168 friend class SkTextBlobBuilder; 168 friend class SkTextBlobBuilder;
169 169
170 void grow(uint32_t count) { 170 void grow(uint32_t count) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); 576 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get()));
577 577
578 this->updateDeferredBounds(); 578 this->updateDeferredBounds();
579 579
580 if (0 == fRunCount) { 580 if (0 == fRunCount) {
581 SkASSERT(nullptr == fStorage.get()); 581 SkASSERT(nullptr == fStorage.get());
582 fStorageUsed = sizeof(SkTextBlob); 582 fStorageUsed = sizeof(SkTextBlob);
583 fStorage.realloc(fStorageUsed); 583 fStorage.realloc(fStorageUsed);
584 } 584 }
585 585
586 const SkTextBlob* blob = new (fStorage.detach()) SkTextBlob(fRunCount, fBoun ds);
587 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;)
588
586 SkDEBUGCODE( 589 SkDEBUGCODE(
587 size_t validateSize = sizeof(SkTextBlob); 590 size_t validateSize = sizeof(SkTextBlob);
588 const SkTextBlob::RunRecord* run = 591 const SkTextBlob::RunRecord* run = SkTextBlob::RunRecord::First(blob);
589 SkTextBlob::RunRecord::First(reinterpret_cast<const SkTextBlob*>(fSt orage.get()));
590 for (int i = 0; i < fRunCount; ++i) { 592 for (int i = 0; i < fRunCount; ++i) {
591 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run- >fPositioning); 593 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run- >fPositioning);
592 run->validate(fStorage.get() + fStorageUsed); 594 run->validate(reinterpret_cast<const uint8_t*>(blob) + fStorageUsed) ;
593 run = SkTextBlob::RunRecord::Next(run); 595 run = SkTextBlob::RunRecord::Next(run);
594 } 596 }
595 SkASSERT(validateSize == fStorageUsed); 597 SkASSERT(validateSize == fStorageUsed);
596 ) 598 )
597 599
598 const SkTextBlob* blob = new (fStorage.detach()) SkTextBlob(fRunCount, fBoun ds);
599 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;)
600
601 fStorageUsed = 0; 600 fStorageUsed = 0;
602 fStorageSize = 0; 601 fStorageSize = 0;
603 fRunCount = 0; 602 fRunCount = 0;
604 fLastRun = 0; 603 fLastRun = 0;
605 fBounds.setEmpty(); 604 fBounds.setEmpty();
606 605
607 return blob; 606 return blob;
608 } 607 }
609 608
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698