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

Unified Diff: src/core/SkPath.cpp

Issue 61913002: Adding error checks to SkRBuffer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added doc Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkFlattenableBuffers.cpp ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPath.cpp
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index c480624a166a287a56701259adf8609c4bdf2dee..a9deb2e2533c1caaa4a6a890ae823b21aec89e6c 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -2082,8 +2082,9 @@ size_t SkPath::writeToMemory(void* storage) const {
(fSegmentMask << kSegmentMask_SerializationShift) |
(fDirection << kDirection_SerializationShift)
#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TOO
- | (0x1 << kNewFormat_SerializationShift);
+ | (0x1 << kNewFormat_SerializationShift)
#endif
+ ;
buffer.write32(packed);
@@ -2096,7 +2097,11 @@ size_t SkPath::writeToMemory(void* storage) const {
size_t SkPath::readFromMemory(const void* storage, size_t length) {
SkRBufferWithSizeCheck buffer(storage, length);
- uint32_t packed = buffer.readS32();
+ int32_t packed;
+ if (!buffer.readS32(&packed)) {
+ return 0;
+ }
+
fIsOval = (packed >> kIsOval_SerializationShift) & 1;
fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF;
fFillType = (packed >> kFillType_SerializationShift) & 0xFF;
@@ -2106,18 +2111,21 @@ size_t SkPath::readFromMemory(const void* storage, size_t length) {
bool newFormat = (packed >> kNewFormat_SerializationShift) & 1;
#endif
- fPathRef.reset(SkPathRef::CreateFromBuffer(&buffer
+ SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer
#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TOO
, newFormat, packed
#endif
- ));
-
- buffer.skipToAlign4();
+ );
size_t sizeRead = 0;
if (buffer.isValid()) {
+ fPathRef.reset(pathRef);
SkDEBUGCODE(this->validate();)
+ buffer.skipToAlign4();
sizeRead = buffer.pos();
+ } else if (NULL != pathRef) {
+ // If the buffer is not valid, pathRef should be NULL
+ sk_throw();
}
return sizeRead;
}
« no previous file with comments | « src/core/SkFlattenableBuffers.cpp ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698