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

Side by Side Diff: pdf/draw_utils.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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "pdf/draw_utils.h" 5 #include "pdf/draw_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <math.h> 8 #include <math.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 start_color, end_color, horizontal); 138 start_color, end_color, horizontal);
139 139
140 pp::Rect copy_rc(draw_rc); 140 pp::Rect copy_rc(draw_rc);
141 copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y()); 141 copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y());
142 AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency); 142 AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency);
143 } 143 }
144 144
145 void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc, 145 void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
146 pp::ImageData* dest, const pp::Rect& dest_rc, 146 pp::ImageData* dest, const pp::Rect& dest_rc,
147 bool stretch) { 147 bool stretch) {
148 DCHECK(src_rc.width() <= dest_rc.width() && 148 if (src_rc.IsEmpty() || !src.Contains(src_rc))
149 src_rc.height() <= dest_rc.height()); 149 return;
150 if (src_rc.IsEmpty()) 150
151 pp::Rect stretched_rc(dest_rc.point(),
152 stretch ? dest_rc.size() : src_rc.size());
153 if (stretched_rc.IsEmpty() || !dest->Contains(stretched_rc))
151 return; 154 return;
152 155
153 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); 156 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
154 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); 157 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point());
155 if (stretch) { 158 if (stretch) {
156 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); 159 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width();
157 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); 160 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height();
158 int32_t height = dest_rc.height(); 161 int32_t height = dest_rc.height();
159 int32_t width = dest_rc.width(); 162 int32_t width = dest_rc.width();
160 for (int32_t y = 0; y < height; ++y) { 163 for (int32_t y = 0; y < height; ++y) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); 322 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
320 323
321 // Fill right part. 324 // Fill right part.
322 rc = pp::Rect(object_rc.right(), object_rc.y(), 325 rc = pp::Rect(object_rc.right(), object_rc.y(),
323 shadow_rc.right() - object_rc.right(), object_rc.height()); 326 shadow_rc.right() - object_rc.right(), object_rc.height());
324 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); 327 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
325 } 328 }
326 329
327 } // namespace chrome_pdf 330 } // namespace chrome_pdf
328 331
OLDNEW
« no previous file with comments | « pdf/control.cc ('k') | ppapi/cpp/image_data.h » ('j') | ppapi/cpp/image_data.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698