aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-11-24 17:00:34 +0100
committerKirill Primak <vyivel@eclair.cafe>2023-11-26 11:56:28 +0000
commit4fbe648fafe687a061e246c2f16b971ecfaf89ec (patch)
treedb053636214db6f2c0164f4209dc109396ab286d
parent7dcb045176ae72140c5e27abeca3e5fde982489c (diff)
viewporter: fix src buffer bounds check
The surface scale and transform are applied before the viewport. Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3766
-rw-r--r--types/wlr_viewporter.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/types/wlr_viewporter.c b/types/wlr_viewporter.c
index cb5d1df1..b66a375f 100644
--- a/types/wlr_viewporter.c
+++ b/types/wlr_viewporter.c
@@ -3,6 +3,7 @@
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_viewporter.h>
#include <wlr/util/log.h>
+#include <wlr/util/transform.h>
#include "viewporter-protocol.h"
#define VIEWPORTER_VERSION 1
@@ -131,6 +132,15 @@ static void viewport_handle_resource_destroy(struct wl_resource *resource) {
viewport_destroy(viewport);
}
+static bool check_src_buffer_bounds(const struct wlr_surface_state *state) {
+ int width = state->buffer_width / state->scale;
+ int height = state->buffer_height / state->scale;
+ wlr_output_transform_coords(state->transform, &width, &height);
+
+ struct wlr_fbox box = state->viewport.src;
+ return box.x + box.width <= width && box.y + box.height <= height;
+}
+
static void viewport_handle_surface_client_commit(struct wl_listener *listener,
void *data) {
struct wlr_viewport *viewport =
@@ -148,10 +158,7 @@ static void viewport_handle_surface_client_commit(struct wl_listener *listener,
}
if (state->viewport.has_src && state->buffer != NULL &&
- (state->viewport.src.x + state->viewport.src.width >
- state->buffer_width ||
- state->viewport.src.y + state->viewport.src.height >
- state->buffer_height)) {
+ !check_src_buffer_bounds(state)) {
wl_resource_post_error(viewport->resource, WP_VIEWPORT_ERROR_OUT_OF_BUFFER,
"source rectangle out of buffer bounds");
return;