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

Unified Diff: include/core/SkReader32.h

Issue 41253002: Checking structure sizes before reading them from memory to avoid overflowing the buffer's stream. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments and added tests Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkRRect.h ('k') | include/core/SkRegion.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkReader32.h
diff --git a/include/core/SkReader32.h b/include/core/SkReader32.h
index 7a8d22a80c166c82539f05fe9d83186269416762..ef2098b9b2056ce50a49e17f01b0f0a5dc954757 100644
--- a/include/core/SkReader32.h
+++ b/include/core/SkReader32.h
@@ -107,26 +107,28 @@ public:
uint32_t readU32() { return this->readInt(); }
void readPath(SkPath* path) {
reed1 2013/10/30 15:37:07 now it seems that all of these read-helpers must r
sugoi1 2013/10/30 18:07:03 Done.
- size_t size = path->readFromMemory(this->peek());
+ size_t size = path->readFromMemory(this->peek(), this->available());
SkASSERT(SkAlign4(size) == size);
- (void)this->skip(size);
+ (void)this->skip(size > 0 ? size : this->available());
reed1 2013/10/30 15:37:07 I think a quick comment in the code would help her
sugoi1 2013/10/30 18:07:03 Done.
}
void readMatrix(SkMatrix* matrix) {
- size_t size = matrix->readFromMemory(this->peek());
+ size_t size = matrix->readFromMemory(this->peek(), this->available());
SkASSERT(SkAlign4(size) == size);
- (void)this->skip(size);
+ (void)this->skip(size > 0 ? size : this->available());
}
SkRRect* readRRect(SkRRect* rrect) {
- rrect->readFromMemory(this->skip(SkRRect::kSizeInMemory));
+ size_t size = rrect->readFromMemory(this->peek(), this->available());
+ SkASSERT(SkAlign4(size) == size);
+ (void)this->skip(size > 0 ? size : this->available());
return rrect;
}
void readRegion(SkRegion* rgn) {
- size_t size = rgn->readFromMemory(this->peek());
+ size_t size = rgn->readFromMemory(this->peek(), this->available());
SkASSERT(SkAlign4(size) == size);
- (void)this->skip(size);
+ (void)this->skip(size > 0 ? size : this->available());
}
/**
« no previous file with comments | « include/core/SkRRect.h ('k') | include/core/SkRegion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698