Fix division by zero in I420Buffer::CropAndScaleFrom

Bug: webrtc:11741
Change-Id: I5ad495084573e55adb77696e6f61880c1378d0c8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178440
Commit-Queue: Dan Minor <dminor@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31799}
This commit is contained in:
Dan Minor 2020-07-27 09:35:52 -04:00 committed by Commit Bot
parent d4089cae47
commit 24a53a05a5

View File

@ -215,9 +215,11 @@ void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src,
void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src) {
const int crop_width =
std::min(src.width(), width() * src.height() / height());
height() > 0 ? std::min(src.width(), width() * src.height() / height())
: src.width();
const int crop_height =
std::min(src.height(), height() * src.width() / width());
width() > 0 ? std::min(src.height(), height() * src.width() / width())
: src.height();
CropAndScaleFrom(src, (src.width() - crop_width) / 2,
(src.height() - crop_height) / 2, crop_width, crop_height);