]> git.nihav.org Git - nihav.git/commitdiff
qtrle: better handling of odd-width paletted frames
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 23 Sep 2026 15:25:38 +0000 (17:25 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 23 Sep 2026 15:25:38 +0000 (17:25 +0200)
nihav-qt/src/codecs/rle.rs

index b7ba94a140f74a8e1ee272d92f22f6dfac0cc934..2b3d7433a2449e7f322132c4a397097b07846268 100644 (file)
@@ -120,7 +120,8 @@ impl RleDecoder {
 
         let stride = frm.stride[0];
         let mut doff = frm.offset[0] + start_line * stride;
-        for _ in start_line..end_line {
+        let awidth = (self.width + npixels - 1) & !(npixels - 1);
+        for _y in start_line..end_line {
             let mut x = 0;
             let mut skip_mode = true;
             while x < self.width {
@@ -130,7 +131,7 @@ impl RleDecoder {
                         return Ok(true);
                     } else {
                         let skip = (skip_code - 1) as usize;
-                        validate!(x + skip * npixels <= self.width);
+                        validate!(x + skip * npixels <= awidth);
                         x += skip * npixels;
                         has_skips = true;
                     }
@@ -146,7 +147,7 @@ impl RleDecoder {
                         break;
                     } else if rle_code < 0 {
                         let len = (-i16::from(rle_code)) as usize;
-                        validate!(x + len * npixels <= self.width);
+                        validate!(x + len * npixels <= awidth);
                         let val             = br.read_u32be()?;
                         unpack_pixels(val, &mut pix_buf, self.depth);
                         for _ in 0..len {
@@ -157,7 +158,7 @@ impl RleDecoder {
                         }
                     } else {
                         let len = rle_code as usize;
-                        validate!(x + len * npixels <= self.width);
+                        validate!(x + len * npixels <= awidth);
                         for _ in 0..len {
                             let val         = br.read_u32be()?;
                             unpack_pixels(val, &mut pix_buf, self.depth);
@@ -169,7 +170,7 @@ impl RleDecoder {
                     }
                 }
             }
-            if x == self.width {
+            if x >= self.width {
                 let eol                 = br.read_byte()? as i8;
                 validate!(eol == -1);
             }