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

Side by Side Diff: ppapi/cpp/image_data.cc

Issue 519873002: Avoid OOB memcpy in chrome_pdf::CopyImage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix underlying math bug. Created 6 years, 3 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
« ppapi/cpp/image_data.h ('K') | « ppapi/cpp/image_data.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 "ppapi/cpp/image_data.h" 5 #include "ppapi/cpp/image_data.h"
6 6
7 #include <string.h> // Needed for memset. 7 #include <string.h> // Needed for memset.
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return const_cast<ImageData*>(this)->GetAddr32(coord); 67 return const_cast<ImageData*>(this)->GetAddr32(coord);
68 } 68 }
69 69
70 uint32_t* ImageData::GetAddr32(const Point& coord) { 70 uint32_t* ImageData::GetAddr32(const Point& coord) {
71 // If we add more image format types that aren't 32-bit, we'd want to check 71 // If we add more image format types that aren't 32-bit, we'd want to check
72 // here and fail. 72 // here and fail.
73 return reinterpret_cast<uint32_t*>( 73 return reinterpret_cast<uint32_t*>(
74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]); 74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]);
75 } 75 }
76 76
77 bool ImageData::Contains(const pp::Rect& rect) const {
78 return rect.width() >= 0 && rect.height() >= 0 &&
79 pp::Rect(size()).Contains(rect);
80 }
81
77 // static 82 // static
78 bool ImageData::IsImageDataFormatSupported(PP_ImageDataFormat format) { 83 bool ImageData::IsImageDataFormatSupported(PP_ImageDataFormat format) {
79 if (!has_interface<PPB_ImageData_1_0>()) 84 if (!has_interface<PPB_ImageData_1_0>())
80 return false; 85 return false;
81 return PP_ToBool(get_interface<PPB_ImageData_1_0>()-> 86 return PP_ToBool(get_interface<PPB_ImageData_1_0>()->
82 IsImageDataFormatSupported(format)); 87 IsImageDataFormatSupported(format));
83 } 88 }
84 89
85 // static 90 // static
86 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { 91 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() {
87 if (!has_interface<PPB_ImageData_1_0>()) 92 if (!has_interface<PPB_ImageData_1_0>())
88 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. 93 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure.
89 return get_interface<PPB_ImageData_1_0>()->GetNativeImageDataFormat(); 94 return get_interface<PPB_ImageData_1_0>()->GetNativeImageDataFormat();
90 } 95 }
91 96
92 void ImageData::InitData() { 97 void ImageData::InitData() {
93 if (!has_interface<PPB_ImageData_1_0>()) 98 if (!has_interface<PPB_ImageData_1_0>())
94 return; 99 return;
95 if (get_interface<PPB_ImageData_1_0>()->Describe(pp_resource(), &desc_)) { 100 if (get_interface<PPB_ImageData_1_0>()->Describe(pp_resource(), &desc_)) {
96 data_ = get_interface<PPB_ImageData_1_0>()->Map(pp_resource()); 101 data_ = get_interface<PPB_ImageData_1_0>()->Map(pp_resource());
97 if (data_) 102 if (data_)
98 return; 103 return;
99 } 104 }
100 *this = ImageData(); 105 *this = ImageData();
101 } 106 }
102 107
103 } // namespace pp 108 } // namespace pp
OLDNEW
« ppapi/cpp/image_data.h ('K') | « ppapi/cpp/image_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698