Skip to content

Commit

Permalink
Preven OOB memory access in chrome_pdf::AlphaBlend().
Browse files Browse the repository at this point in the history
Similar to bug 398384, but perform the same bounds check we introduced to
chrome_pdf::CopyImage() in the chrome_pdf::AlphaBlend() function.

Also change the return value from bool to void, since AlphaBlend() always
returns true, and no-one was checking the return value anyways.

BUG=384891

Review URL: https://codereview.chromium.org/544863002

Cr-Commit-Position: refs/heads/master@{#293454}
  • Loading branch information
tsepez authored and Commit bot committed Sep 5, 2014
1 parent 37fac50 commit 8f07983
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pdf/draw_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ inline bool ImageDataContainsRect(const pp::ImageData& image_data,
pp::Rect(image_data.size()).Contains(rect);
}

bool AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
pp::ImageData* dest, const pp::Point& dest_origin,
uint8 alpha_adjustment) {
if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc))
return;

pp::Rect dest_rc(dest_origin, src_rc.size());
if (dest_rc.IsEmpty() || !ImageDataContainsRect(*dest, dest_rc))
return;

const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
uint32_t* dest_origin_pixel = dest->GetAddr32(dest_origin);

Expand All @@ -86,7 +93,6 @@ bool AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
dest_origin_pixel = reinterpret_cast<uint32_t*>(
reinterpret_cast<char*>(dest_origin_pixel) + dest->stride());
}
return true;
}

void GradientFill(pp::ImageData* image, const pp::Rect& rc,
Expand Down
2 changes: 1 addition & 1 deletion pdf/draw_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace chrome_pdf {
const uint8 kOpaqueAlpha = 0xFF;
const uint8 kTransparentAlpha = 0x00;

bool AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
pp::ImageData* dest, const pp::Point& dest_origin,
uint8 alpha_adjustment);

Expand Down

0 comments on commit 8f07983

Please sign in to comment.