Skip to content

Commit

Permalink
FlatlandClientNativePixmapFactory: make sure stride is int.
Browse files Browse the repository at this point in the history
This CL adds a check to
FlatlandClientNativePixmapFactory::ImportFromHandle() to make sure the
stride of each plane being imported can fit into an int so that it
works with the GpuMemoryBuffer::stride() API. Note that this is
consistent with the check in
ScenicClientNativePixmapFactory::ImportFromHandle().

Bug: 1237496
Test: None
Change-Id: Ia8b6fc37184ff3cd00c71635cfebc97be5e6ad6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3077470
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#911443}
  • Loading branch information
andrescj-chromium authored and Chromium LUCI CQ committed Aug 12, 2021
1 parent 9389ae4 commit b59e729
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ClientNativePixmapFuchsia : public gfx::ClientNativePixmap {

int GetStride(size_t plane) const override {
DCHECK_LT(plane, handle_.planes.size());
return handle_.planes[plane].stride;
return base::checked_cast<int>(handle_.planes[plane].stride);
}

gfx::NativePixmapHandle CloneHandleForIPC() const override {
Expand Down Expand Up @@ -151,6 +151,11 @@ class FlatlandClientNativePixmapFactory
return nullptr;
}

// The stride must be a valid integer in order to be consistent with the
// gfx::ClientNativePixmap::GetStride() API.
if (!base::IsValueInRangeForNumericType<int>(handle.planes[i].stride))
return nullptr;

base::CheckedNumeric<size_t> min_size =
base::CheckedNumeric<size_t>(handle.planes[i].stride) * plane_height;
if (!min_size.IsValid() || handle.planes[i].size < min_size.ValueOrDie())
Expand Down

0 comments on commit b59e729

Please sign in to comment.