Improved SkPathRef interface security
https://codereview.chromium.org/115323004/
git-svn-id: http://skia.googlecode.com/svn/trunk/include@12676 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkPath.h b/core/SkPath.h
index 1526461..9b3f281 100644
--- a/core/SkPath.h
+++ b/core/SkPath.h
@@ -1005,7 +1005,9 @@
// 'rect' needs to be sorted
void setBounds(const SkRect& rect) {
- fPathRef->setBounds(rect);
+ SkPathRef::Editor ed(&fPathRef);
+
+ ed.setBounds(rect);
}
#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
diff --git a/core/SkPathRef.h b/core/SkPathRef.h
index 99fd90a..c55f549 100644
--- a/core/SkPathRef.h
+++ b/core/SkPathRef.h
@@ -49,7 +49,8 @@
/**
* Returns the array of points.
*/
- SkPoint* points() { return fPathRef->fPoints; }
+ SkPoint* points() { return fPathRef->getPoints(); }
+ const SkPoint* points() const { return fPathRef->points(); }
/**
* Gets the ith point. Shortcut for this->points() + i
@@ -58,6 +59,10 @@
SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt);
return this->points() + i;
};
+ const SkPoint* atPoint(int i) const {
+ SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt);
+ return this->points() + i;
+ };
/**
* Adds the verb and allocates space for the number of points indicated by the verb. The
@@ -89,6 +94,7 @@
void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) {
fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
}
+
/**
* Gets the path ref that is wrapped in the Editor.
*/
@@ -96,6 +102,8 @@
void setIsOval(bool isOval) { fPathRef->setIsOval(isOval); }
+ void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); }
+
private:
SkPathRef* fPathRef;
};
@@ -158,13 +166,6 @@
return fBounds;
}
- void setBounds(const SkRect& rect) {
- SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom);
- fBounds = rect;
- fBoundsIsDirty = false;
- fIsFinite = fBounds.isFinite();
- }
-
/**
* Transforms a path ref by a matrix, allocating a new one only if necessary.
*/
@@ -299,6 +300,13 @@
fBoundsIsDirty = false;
}
+ void setBounds(const SkRect& rect) {
+ SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom);
+ fBounds = rect;
+ fBoundsIsDirty = false;
+ fIsFinite = fBounds.isFinite();
+ }
+
/** Makes additional room but does not change the counts or change the genID */
void incReserve(int additionalVerbs, int additionalPoints) {
SkDEBUGCODE(this->validate();)
@@ -418,6 +426,12 @@
void setIsOval(bool isOval) { fIsOval = isOval; }
+ SkPoint* getPoints() {
+ SkDEBUGCODE(this->validate();)
+ fIsOval = false;
+ return fPoints;
+ }
+
enum {
kMinSize = 256,
};
@@ -441,6 +455,7 @@
mutable uint32_t fGenerationID;
SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
+ friend class PathRefTest_Private;
typedef SkRefCnt INHERITED;
};