diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc index 64de9ae8c63b8..23154fb50016d 100644 --- a/media/base/video_frame.cc +++ b/media/base/video_frame.cc @@ -1297,7 +1297,7 @@ base::span VideoFrame::GetVisibleDataInternal(base::span data, base::bits::AlignDownDeprecatedDoNotUse( visible_rect_.y(), alignment.height())); - const int plane_stride = stride(plane); + const int plane_stride = base::checked_cast(stride(plane)); const gfx::Size subsample = SampleSize(format(), plane); DCHECK(offset.x() % subsample.width() == 0); DCHECK(offset.y() % subsample.height() == 0); diff --git a/media/gpu/chromeos/video_frame_resource.cc b/media/gpu/chromeos/video_frame_resource.cc index 09e919ffd2c25..3b3972fc77304 100644 --- a/media/gpu/chromeos/video_frame_resource.cc +++ b/media/gpu/chromeos/video_frame_resource.cc @@ -6,6 +6,7 @@ #include "base/functional/callback_helpers.h" #include "base/memory/scoped_refptr.h" +#include "base/numerics/safe_conversions.h" #include "base/types/pass_key.h" #include "media/gpu/chromeos/platform_video_frame_utils.h" @@ -100,7 +101,10 @@ VideoPixelFormat VideoFrameResource::format() const { } int VideoFrameResource::stride(size_t plane) const { - return frame_->stride(plane); + // VideoFrame::stride() returns size_t. An implicit narrowing here turns + // renderer-controlled values >= 2^31 into negative ints, which propagate to + // libyuv and cause out-of-bounds reads. CHECK on overflow instead. + return base::checked_cast(frame_->stride(plane)); } VideoFrame::StorageType VideoFrameResource::storage_type() const {