[gtk-vnc] src: use framebuffer dimensions for validating framebuffer updates



commit 9b190de579cee81af5be9e26be96f85f2ba6f2c6
Author: Daniel P. Berrangé <dan berrange com>
Date:   Tue Dec 8 12:20:48 2020 +0000

    src: use framebuffer dimensions for validating framebuffer updates
    
    The framebuffer size would match the remote desktop size at all times so
    there is no functional change here. This will be useful, however, when
    the update code is reused for decoding data unrelated to the primary
    desktop.
    
    Signed-off-by: Daniel P. Berrangé <berrange redhat com>

 src/vncconnection.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index c3069e3..e16fbe4 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -2148,15 +2148,17 @@ static vnc_connection_tight_sum_pixel_func *vnc_connection_tight_sum_pixel_table
 };
 
 static gboolean vnc_connection_validate_boundary(VncConnection *conn,
+                                                 VncFramebuffer *fb,
                                                  guint16 x, guint16 y,
                                                  guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
+    guint16 fbwidth = vnc_framebuffer_get_width(fb);
+    guint16 fbheight = vnc_framebuffer_get_height(fb);
 
-    if ((x + width) > priv->width || (y + height) > priv->height) {
+    if ((x + width) > fbwidth || (y + height) > fbheight) {
         vnc_connection_set_error(conn, "Framebuffer update %dx%d at %d,%d "
                                  "outside boundary %dx%d",
-                                 width, height, x, y, priv->width, priv->height);
+                                 width, height, x, y, fbwidth, fbheight);
     }
 
     return !vnc_connection_has_error(conn);
@@ -2209,7 +2211,8 @@ static void vnc_connection_copyrect_update(VncConnection *conn,
     src_x = vnc_connection_read_u16(conn);
     src_y = vnc_connection_read_u16(conn);
 
-    if (!vnc_connection_validate_boundary(conn, src_x, src_y, width, height))
+    if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                          src_x, src_y, width, height))
         return;
 
     vnc_framebuffer_copyrect(priv->fb,
@@ -2254,7 +2257,8 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
                 xy = vnc_connection_read_u8(conn);
                 wh = vnc_connection_read_u8(conn);
 
-                if (!vnc_connection_validate_boundary(conn, x + nibhi(xy), y + niblo(xy),
+                if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                                      x + nibhi(xy), y + niblo(xy),
                                                       nibhi(wh) + 1, niblo(wh) + 1))
                     return;
 
@@ -2314,7 +2318,8 @@ static void vnc_connection_rre_update(VncConnection *conn,
         sub_w = vnc_connection_read_u16(conn);
         sub_h = vnc_connection_read_u16(conn);
 
-        if (!vnc_connection_validate_boundary(conn, x + sub_x, y + sub_y, sub_w, sub_h))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x + sub_x, y + sub_y, sub_w, sub_h))
             break;
 
         vnc_framebuffer_fill(priv->fb, fg,
@@ -3116,37 +3121,43 @@ static gboolean vnc_connection_framebuffer_update(VncConnection *conn, gint32 et
 
     switch (etype) {
     case VNC_CONNECTION_ENCODING_RAW:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_raw_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_COPY_RECT:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_copyrect_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_RRE:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_rre_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_HEXTILE:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_hextile_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_ZRLE:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_zrle_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_TIGHT:
-        if (!vnc_connection_validate_boundary(conn, x, y, width, height))
+        if (!vnc_connection_validate_boundary(conn, priv->fb,
+                                              x, y, width, height))
             break;
         vnc_connection_tight_update(conn, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]