Skip to content

Commit

Permalink
WlShmBuffer: Guard against definitely-invalid strides.
Browse files Browse the repository at this point in the history
This fixes the wlcs test BadBufferTest.client_lies_about_buffer_size
  • Loading branch information
RAOF authored and AlanGriffiths committed Dec 12, 2017
1 parent f0557e7 commit 1b47acc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/server/frontend/wayland/wayland_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ class WlShmBuffer :
consumed{false},
on_consumed{std::move(on_consumed)}
{
if (stride_.as_int() < size_.width.as_int() * MIR_BYTES_PER_PIXEL(format_))
{
wl_resource_post_error(
resource,
WL_SHM_ERROR_INVALID_STRIDE,
"Stride (%u) is less than width × bytes per pixel (%u×%u). "
"Did you accidentally specify stride in pixels?",
stride_.as_int(), size_.width.as_int(), MIR_BYTES_PER_PIXEL(format_));

BOOST_THROW_EXCEPTION((
std::runtime_error{"Buffer has invalid stride"}));
}

wl_shm_buffer_begin_access(this->buffer);
std::memcpy(data.get(), wl_shm_buffer_get_data(this->buffer), size_.height.as_int() * stride_.as_int());
wl_shm_buffer_end_access(this->buffer);
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance-tests/wayland/wlcs
Submodule wlcs updated from eee81a to 4bef07

0 comments on commit 1b47acc

Please sign in to comment.