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

Side by Side Diff: gpu/command_buffer/service/common_decoder.cc

Issue 822953002: Validate Bucket data in ShaderSourceBucket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added braces to error check. Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/service/common_decoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/common_decoder.h" 5 #include "gpu/command_buffer/service/common_decoder.h"
6 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 6 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
7 7
8 namespace gpu { 8 namespace gpu {
9 9
10 CommonDecoder::Bucket::Bucket() : size_(0) {} 10 CommonDecoder::Bucket::Bucket() : size_(0) {}
11 11
12 CommonDecoder::Bucket::~Bucket() {} 12 CommonDecoder::Bucket::~Bucket() {}
13 13
14 void* CommonDecoder::Bucket::GetData(size_t offset, size_t size) const { 14 void* CommonDecoder::Bucket::GetData(size_t offset, size_t size) const {
15 if (OffsetSizeValid(offset, size)) { 15 if (OffsetSizeValid(offset, size)) {
16 return data_.get() + offset; 16 return data_.get() + offset;
17 } 17 }
18 return NULL; 18 return NULL;
19 } 19 }
20 20
21 void CommonDecoder::Bucket::SetSize(size_t size) { 21 bool CommonDecoder::Bucket::SetSize(size_t size) {
22 if (size != size_) { 22 if (size != size_) {
23 data_.reset(size ? new int8[size] : NULL); 23 data_.reset(size ? new int8[size] : NULL);
24 if (!data_.get() && (size != 0)) {
25 size_ = 0;
26 return false;
27 }
24 size_ = size; 28 size_ = size;
25 memset(data_.get(), 0, size); 29 memset(data_.get(), 0, size);
26 } 30 }
31 return true;
27 } 32 }
28 33
29 bool CommonDecoder::Bucket::SetData( 34 bool CommonDecoder::Bucket::SetData(
30 const void* src, size_t offset, size_t size) { 35 const void* src, size_t offset, size_t size) {
31 if (OffsetSizeValid(offset, size)) { 36 if (OffsetSizeValid(offset, size)) {
32 memcpy(data_.get() + offset, src, size); 37 memcpy(data_.get() + offset, src, size);
33 return true; 38 return true;
34 } 39 }
35 return false; 40 return false;
36 } 41 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return error::kNoError; 184 return error::kNoError;
180 } 185 }
181 186
182 error::Error CommonDecoder::HandleSetBucketSize( 187 error::Error CommonDecoder::HandleSetBucketSize(
183 uint32 immediate_data_size, 188 uint32 immediate_data_size,
184 const cmd::SetBucketSize& args) { 189 const cmd::SetBucketSize& args) {
185 uint32 bucket_id = args.bucket_id; 190 uint32 bucket_id = args.bucket_id;
186 uint32 size = args.size; 191 uint32 size = args.size;
187 192
188 Bucket* bucket = CreateBucket(bucket_id); 193 Bucket* bucket = CreateBucket(bucket_id);
189 bucket->SetSize(size); 194 if (!bucket->SetSize(size)) {
195 return error::kOutOfBounds;
196 }
190 return error::kNoError; 197 return error::kNoError;
191 } 198 }
192 199
193 error::Error CommonDecoder::HandleSetBucketData( 200 error::Error CommonDecoder::HandleSetBucketData(
194 uint32 immediate_data_size, 201 uint32 immediate_data_size,
195 const cmd::SetBucketData& args) { 202 const cmd::SetBucketData& args) {
196 uint32 bucket_id = args.bucket_id; 203 uint32 bucket_id = args.bucket_id;
197 uint32 offset = args.offset; 204 uint32 offset = args.offset;
198 uint32 size = args.size; 205 uint32 size = args.size;
199 const void* data = GetSharedMemoryAs<const void*>( 206 const void* data = GetSharedMemoryAs<const void*>(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 293 }
287 const void* src = bucket->GetData(offset, size); 294 const void* src = bucket->GetData(offset, size);
288 if (!src) { 295 if (!src) {
289 return error::kInvalidArguments; 296 return error::kInvalidArguments;
290 } 297 }
291 memcpy(data, src, size); 298 memcpy(data, src, size);
292 return error::kNoError; 299 return error::kNoError;
293 } 300 }
294 301
295 } // namespace gpu 302 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/common_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698