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

Unified 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: Rename function for clarity. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pdf/control.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/draw_utils.cc
diff --git a/pdf/draw_utils.cc b/pdf/draw_utils.cc
index 8bc3ac3ae1e6b12c9ceac5a0079980f7d363aef3..7f999f060d49f334a291634374f4f6413a662e2a 100644
--- a/pdf/draw_utils.cc
+++ b/pdf/draw_utils.cc
@@ -51,6 +51,12 @@ inline uint8 ProcessColor(uint8 src_color, uint8 dest_color, uint8 alpha) {
return static_cast<uint8>((processed / 0xFF) & 0xFF);
}
+inline bool ImageDataContainsRect(const pp::ImageData& image_data,
+ const pp::Rect& rect) {
+ return rect.width() >= 0 && rect.height() >= 0 &&
+ pp::Rect(image_data.size()).Contains(rect);
+}
+
bool AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
pp::ImageData* dest, const pp::Point& dest_origin,
uint8 alpha_adjustment) {
@@ -145,9 +151,12 @@ void GradientFill(pp::Instance* instance,
void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
pp::ImageData* dest, const pp::Rect& dest_rc,
bool stretch) {
- DCHECK(src_rc.width() <= dest_rc.width() &&
- src_rc.height() <= dest_rc.height());
- if (src_rc.IsEmpty())
+ if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc))
+ return;
+
+ pp::Rect stretched_rc(dest_rc.point(),
+ stretch ? dest_rc.size() : src_rc.size());
+ if (stretched_rc.IsEmpty() || !ImageDataContainsRect(*dest, stretched_rc))
return;
const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
« no previous file with comments | « pdf/control.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698