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

Side by Side Diff: src/core/SkBuffer.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 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 8
9 9
10 #include "SkBuffer.h" 10 #include "SkBuffer.h"
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 size_t SkRBuffer::skipToAlign4() 29 size_t SkRBuffer::skipToAlign4()
30 { 30 {
31 size_t pos = this->pos(); 31 size_t pos = this->pos();
32 size_t n = SkAlign4(pos) - pos; 32 size_t n = SkAlign4(pos) - pos;
33 fPos += n; 33 fPos += n;
34 return n; 34 return n;
35 } 35 }
36 36
37 void SkRBufferWithSizeCheck::read(void* buffer, size_t size) {
38 fError = fError || (fPos + size > fStop);
39 if (!fError && (size > 0)) {
40 readNoSizeCheck(buffer, size);
41 }
42 }
43
37 void* SkWBuffer::skip(size_t size) 44 void* SkWBuffer::skip(size_t size)
38 { 45 {
39 void* result = fPos; 46 void* result = fPos;
40 writeNoSizeCheck(NULL, size); 47 writeNoSizeCheck(NULL, size);
41 return fData == NULL ? NULL : result; 48 return fData == NULL ? NULL : result;
42 } 49 }
43 50
44 void SkWBuffer::writeNoSizeCheck(const void* buffer, size_t size) 51 void SkWBuffer::writeNoSizeCheck(const void* buffer, size_t size)
45 { 52 {
46 SkASSERT(fData == 0 || fStop == 0 || fPos + size <= fStop); 53 SkASSERT(fData == 0 || fStop == 0 || fPos + size <= fStop);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 127
121 const void* sk_buffer_read_ptr(const void* buffer, void** ptr) 128 const void* sk_buffer_read_ptr(const void* buffer, void** ptr)
122 { 129 {
123 AssertBuffer32(buffer); 130 AssertBuffer32(buffer);
124 if (ptr) 131 if (ptr)
125 *ptr = *(void**)buffer; 132 *ptr = *(void**)buffer;
126 return (const char*)buffer + sizeof(void*); 133 return (const char*)buffer + sizeof(void*);
127 } 134 }
128 135
129 #endif 136 #endif
OLDNEW
« no previous file with comments | « src/core/SkBuffer.h ('k') | src/core/SkMatrix.cpp » ('j') | tests/SerializationTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698