All of lore.kernel.org
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: peter.maydell@linaro.org, qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
	Helge Deller <deller@gmx.de>,
	Sven Schnelle <svens@stackframe.org>,
	Richard Henderson <rth@twiddle.net>
Subject: [PATCH v3 4/8] hw/display/artist.c: fix out of bounds check
Date: Tue,  4 Aug 2020 16:00:52 +0200	[thread overview]
Message-ID: <20200804140056.7690-5-deller@gmx.de> (raw)
In-Reply-To: <20200804140056.7690-1-deller@gmx.de>

From: Sven Schnelle <svens@stackframe.org>

Fix the following runtime warning with artist framebuffer:
"write outside bounds: wants 1256x1023, max size 1280x1024"

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 hw/display/artist.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/hw/display/artist.c b/hw/display/artist.c
index 6261bfe65b..de56200dbf 100644
--- a/hw/display/artist.c
+++ b/hw/display/artist.c
@@ -340,14 +340,13 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
 {
     struct vram_buffer *buf;
     uint32_t vram_bitmask = s->vram_bitmask;
-    int mask, i, pix_count, pix_length, offset, height, width;
+    int mask, i, pix_count, pix_length, offset, width;
     uint8_t *data8, *p;

     pix_count = vram_write_pix_per_transfer(s);
     pix_length = vram_pixel_length(s);

     buf = vram_write_buffer(s);
-    height = buf->height;
     width = buf->width;

     if (s->cmap_bm_access) {
@@ -367,13 +366,6 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         pix_count = size * 8;
     }

-    if (posy * width + posx + pix_count > buf->size) {
-        qemu_log("write outside bounds: wants %dx%d, max size %dx%d\n",
-                 posx, posy, width, height);
-        return;
-    }
-
-
     switch (pix_length) {
     case 0:
         if (s->image_bitmap_op & 0x20000000) {
@@ -381,8 +373,11 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         }

         for (i = 0; i < pix_count; i++) {
-            artist_rop8(s, p + offset + pix_count - 1 - i,
-                        (data & 1) ? (s->plane_mask >> 24) : 0);
+            uint32_t off = offset + pix_count - 1 - i;
+            if (off < buf->size) {
+                artist_rop8(s, p + off,
+                            (data & 1) ? (s->plane_mask >> 24) : 0);
+            }
             data >>= 1;
         }
         memory_region_set_dirty(&buf->mr, offset, pix_count);
@@ -398,7 +393,10 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         for (i = 3; i >= 0; i--) {
             if (!(s->image_bitmap_op & 0x20000000) ||
                 s->vram_bitmask & (1 << (28 + i))) {
-                artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                uint32_t off = offset + 3 - i;
+                if (off < buf->size) {
+                    artist_rop8(s, p + off, data8[ROP8OFF(i)]);
+                }
             }
         }
         memory_region_set_dirty(&buf->mr, offset, 3);
@@ -420,7 +418,7 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
             break;
         }

-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             mask = 1 << (pix_count - 1 - i);

             if (!(s->image_bitmap_op & 0x20000000) ||
--
2.21.3



  parent reply	other threads:[~2020-08-04 14:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-04 14:00 [PATCH v3 0/8] target-hppa fixes v3 Helge Deller
2020-08-04 14:00 ` [PATCH v3 1/8] hw/hppa: Sync hppa_hardware.h file with SeaBIOS sources Helge Deller
2020-08-04 14:00 ` [PATCH v3 2/8] seabios-hppa: Update to SeaBIOS hppa version 1 Helge Deller
2020-08-04 14:00 ` [PATCH v3 3/8] hw/hppa: Implement proper SeaBIOS version check Helge Deller
2020-08-04 14:00 ` Helge Deller [this message]
2020-08-04 16:40   ` [PATCH v3 4/8] hw/display/artist.c: fix out of bounds check Alexander Bulekov
2020-08-04 14:00 ` [PATCH v3 5/8] hw/hppa/lasi: Don't abort on invalid IMR value Helge Deller
2020-08-04 14:00 ` [PATCH v3 6/8] hw/display/artist: Check offset in draw_line to avoid buffer over-run Helge Deller
2020-08-04 14:00 ` [PATCH v3 7/8] hw/display/artist: Refactor artist_rop8() " Helge Deller
2020-08-04 16:39   ` Alexander Bulekov
2020-08-04 21:20     ` Helge Deller
2020-08-04 22:01       ` Alexander Bulekov
2020-08-05  4:33         ` Alexander Bulekov
2020-08-05 20:44         ` Helge Deller
2020-08-06 15:46           ` Alexander Bulekov
2020-08-09  5:17             ` Helge Deller
2020-08-09 17:17               ` Alexander Bulekov
2020-08-09 19:38                 ` Helge Deller
2020-08-09 19:51                   ` Helge Deller
2020-08-09 23:52                     ` [PATCH v3 7/8] hw/display/artist: Refactor artist_rop8() to avoid buffer over-runy Alexander Bulekov
2020-08-04 14:00 ` [PATCH v3 8/8] hw/display/artist: Prevent out of VRAM buffer accesses Helge Deller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200804140056.7690-5-deller@gmx.de \
    --to=deller@gmx.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=rth@twiddle.net \
    --cc=svens@stackframe.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.