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

Side by Side Diff: pdf/draw_utils.cc

Issue 544863002: Preven OOB memory access in chrome_pdf::AlphaBlend(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « pdf/draw_utils.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) 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 static_cast<uint32>(dest_color) * (0xFF - alpha); 50 static_cast<uint32>(dest_color) * (0xFF - alpha);
51 return static_cast<uint8>((processed / 0xFF) & 0xFF); 51 return static_cast<uint8>((processed / 0xFF) & 0xFF);
52 } 52 }
53 53
54 inline bool ImageDataContainsRect(const pp::ImageData& image_data, 54 inline bool ImageDataContainsRect(const pp::ImageData& image_data,
55 const pp::Rect& rect) { 55 const pp::Rect& rect) {
56 return rect.width() >= 0 && rect.height() >= 0 && 56 return rect.width() >= 0 && rect.height() >= 0 &&
57 pp::Rect(image_data.size()).Contains(rect); 57 pp::Rect(image_data.size()).Contains(rect);
58 } 58 }
59 59
60 bool AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc, 60 void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
61 pp::ImageData* dest, const pp::Point& dest_origin, 61 pp::ImageData* dest, const pp::Point& dest_origin,
62 uint8 alpha_adjustment) { 62 uint8 alpha_adjustment) {
63 if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc))
64 return;
65
66 pp::Rect dest_rc(dest_origin, src_rc.size());
67 if (dest_rc.IsEmpty() || !ImageDataContainsRect(*dest, dest_rc))
68 return;
69
63 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); 70 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
64 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_origin); 71 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_origin);
65 72
66 int height = src_rc.height(); 73 int height = src_rc.height();
67 int width = src_rc.width(); 74 int width = src_rc.width();
68 for (int y = 0; y < height; y++) { 75 for (int y = 0; y < height; y++) {
69 const uint32_t* src_pixel = src_origin_pixel; 76 const uint32_t* src_pixel = src_origin_pixel;
70 uint32_t* dest_pixel = dest_origin_pixel; 77 uint32_t* dest_pixel = dest_origin_pixel;
71 for (int x = 0; x < width; x++) { 78 for (int x = 0; x < width; x++) {
72 uint8 alpha = static_cast<uint8>(static_cast<uint32_t>(alpha_adjustment) * 79 uint8 alpha = static_cast<uint8>(static_cast<uint32_t>(alpha_adjustment) *
73 GetAlpha(*src_pixel) / 0xFF); 80 GetAlpha(*src_pixel) / 0xFF);
74 uint8 red = ProcessColor(GetRed(*src_pixel), GetRed(*dest_pixel), alpha); 81 uint8 red = ProcessColor(GetRed(*src_pixel), GetRed(*dest_pixel), alpha);
75 uint8 green = ProcessColor(GetGreen(*src_pixel), 82 uint8 green = ProcessColor(GetGreen(*src_pixel),
76 GetGreen(*dest_pixel), alpha); 83 GetGreen(*dest_pixel), alpha);
77 uint8 blue = ProcessColor(GetBlue(*src_pixel), 84 uint8 blue = ProcessColor(GetBlue(*src_pixel),
78 GetBlue(*dest_pixel), alpha); 85 GetBlue(*dest_pixel), alpha);
79 *dest_pixel = MakePixel(red, green, blue, GetAlpha(*dest_pixel)); 86 *dest_pixel = MakePixel(red, green, blue, GetAlpha(*dest_pixel));
80 87
81 src_pixel++; 88 src_pixel++;
82 dest_pixel++; 89 dest_pixel++;
83 } 90 }
84 src_origin_pixel = reinterpret_cast<const uint32_t*>( 91 src_origin_pixel = reinterpret_cast<const uint32_t*>(
85 reinterpret_cast<const char*>(src_origin_pixel) + src.stride()); 92 reinterpret_cast<const char*>(src_origin_pixel) + src.stride());
86 dest_origin_pixel = reinterpret_cast<uint32_t*>( 93 dest_origin_pixel = reinterpret_cast<uint32_t*>(
87 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); 94 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride());
88 } 95 }
89 return true;
90 } 96 }
91 97
92 void GradientFill(pp::ImageData* image, const pp::Rect& rc, 98 void GradientFill(pp::ImageData* image, const pp::Rect& rc,
93 uint32 start_color, uint32 end_color, bool horizontal) { 99 uint32 start_color, uint32 end_color, bool horizontal) {
94 std::vector<uint32> colors; 100 std::vector<uint32> colors;
95 colors.resize(horizontal ? rc.width() : rc.height()); 101 colors.resize(horizontal ? rc.width() : rc.height());
96 for (size_t i = 0; i < colors.size(); ++i) { 102 for (size_t i = 0; i < colors.size(); ++i) {
97 double ratio = static_cast<double>(i) / colors.size(); 103 double ratio = static_cast<double>(i) / colors.size();
98 colors[i] = MakePixel( 104 colors[i] = MakePixel(
99 GradientChannel(GetRed(start_color), GetRed(end_color), ratio), 105 GradientChannel(GetRed(start_color), GetRed(end_color), ratio),
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); 334 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
329 335
330 // Fill right part. 336 // Fill right part.
331 rc = pp::Rect(object_rc.right(), object_rc.y(), 337 rc = pp::Rect(object_rc.right(), object_rc.y(),
332 shadow_rc.right() - object_rc.right(), object_rc.height()); 338 shadow_rc.right() - object_rc.right(), object_rc.height());
333 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); 339 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
334 } 340 }
335 341
336 } // namespace chrome_pdf 342 } // namespace chrome_pdf
337 343
OLDNEW
« no previous file with comments | « pdf/draw_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698