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

Side by Side Diff: samplecode/SampleRegion.cpp

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: Adding validation before memory allocation in SkRegion::readFromMemory 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 tmp.translate(5, -3); 273 tmp.translate(5, -3);
274 274
275 { 275 {
276 char buffer[1000]; 276 char buffer[1000];
277 SkDEBUGCODE(size_t size = ) tmp.writeToMemory(NULL); 277 SkDEBUGCODE(size_t size = ) tmp.writeToMemory(NULL);
278 SkASSERT(size <= sizeof(buffer)); 278 SkASSERT(size <= sizeof(buffer));
279 SkDEBUGCODE(size_t size2 = ) tmp.writeToMemory(buffer); 279 SkDEBUGCODE(size_t size2 = ) tmp.writeToMemory(buffer);
280 SkASSERT(size == size2); 280 SkASSERT(size == size2);
281 281
282 SkRegion tmp3; 282 SkRegion tmp3;
283 SkDEBUGCODE(size2 = ) tmp3.readFromMemory(buffer); 283 SkDEBUGCODE(size2 = ) tmp3.readFromMemory(buffer, 1000);
284 SkASSERT(size == size2); 284 SkASSERT(size == size2);
285 285
286 SkASSERT(tmp3 == tmp); 286 SkASSERT(tmp3 == tmp);
287 } 287 }
288 288
289 rgn.translate(20, 30, &tmp); 289 rgn.translate(20, 30, &tmp);
290 SkASSERT(rgn.isEmpty() || tmp != rgn); 290 SkASSERT(rgn.isEmpty() || tmp != rgn);
291 tmp.translate(-20, -30); 291 tmp.translate(-20, -30);
292 SkASSERT(tmp == rgn); 292 SkASSERT(tmp == rgn);
293 } 293 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 private: 409 private:
410 SkIRect fBase, fRect; 410 SkIRect fBase, fRect;
411 411
412 typedef SampleView INHERITED; 412 typedef SampleView INHERITED;
413 }; 413 };
414 414
415 ////////////////////////////////////////////////////////////////////////////// 415 //////////////////////////////////////////////////////////////////////////////
416 416
417 static SkView* MyFactory() { return new RegionView; } 417 static SkView* MyFactory() { return new RegionView; }
418 static SkViewRegister reg(MyFactory); 418 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkRegion.h ('k') | src/core/SkBuffer.h » ('j') | tests/SerializationTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698