Hi,

Attached are DEP-3 patches for CVE-2026-121942 (out-of-bounds read in the SQ
code decoder).

Root cause: in _zbar_sq_decode() (zbar/sqcode.c) each per-pixel sample
position is computed by bilinear interpolation of the detected border-dot
centres. For a perspective-distorted code the interpolated coordinate can
land outside the image, and a negative intermediate additionally makes the
following float-to-unsigned conversion undefined. The resulting value was
used directly as an index into img->data, so a crafted grayscale (Y800)
image with a skewed SQ finder pattern near an edge reads past the image
buffer (CWE-125): the decoder can crash, and the out-of-bounds pixel values
feed into the decoded output, which can leak adjacent heap bytes. The path
is reachable from the public zbar_scan_image() with no special
configuration,
since SQ code is in the default build.

Fix: clamp both sample axes to [0, width-1] / [0, height-1] before each
image
access, and reject negative coordinates before the unsigned conversion. This
mirrors the QR_CLAMPI() guard that the sibling QR decoder has long used in
qr_img_get_bit(). In-range coordinates are returned unchanged, so legitimate
codes decode identically; only the previously out-of-bounds accesses change.

Attached:
CVE-2026-121942-sid-trixie.patch applies to 0.23.95-2 (sid) and
0.23.93-8 (trixie)
CVE-2026-121942-bookworm.patch applies to 0.23.92-7+deb12u1 (bookworm)

The two differ only in the surrounding indentation/declaration style of the
respective branch; the logical change is identical. I confirmed each applies
cleanly to the packaged source, and verified the clamp helper in isolation
(negative, oversized and boundary inputs all map to a valid in-range index,
and in-range values are returned unchanged). I did not rebuild each package
separately. The fix is also suitable for forwarding upstream.

Regards,
Sumit
Description: Bound SQ code sampling coordinates to the image (CVE-2026-121942)
 The SQ code decoder in _zbar_sq_decode() (zbar/sqcode.c) derives each pixel
 sample position by bilinear interpolation of the detected border-dot centres.
 For a perspective-distorted code those interpolated coordinates can fall
 outside the image, and a negative result additionally makes the following
 float-to-unsigned conversion undefined.  The raw value was used directly as
 an index into img->data, so a crafted grayscale (Y800) image with a skewed SQ
 finder pattern near an edge caused an out-of-bounds heap read (CWE-125),
 crashing the decoder and potentially leaking adjacent heap bytes into the
 decoded output.
 .
 Clamp both axes to [0, width-1] / [0, height-1] before indexing, mirroring the
 QR_CLAMPI() guard already used by qr_img_get_bit() in the QR decoder.  In-range
 coordinates are returned unchanged, so legitimate codes decode identically.
Author: Sumit Verma <[email protected]>
Bug: https://github.com/mchehab/zbar/issues/351
Bug-Debian: https://bugs.debian.org/1153258
Forwarded: no
Last-Update: 2026-11-06
--- a/zbar/sqcode.c
+++ b/zbar/sqcode.c
@@ -297,6 +297,22 @@ bool find_bottom_dot(zbar_image_t *img, sq_dot *dot, unsigned *found_x,
     return false;
 }
 
+/* Clamp a floating-point sample coordinate to a valid pixel index in
+   [0, dim - 1].  The SQ code border interpolation in _zbar_sq_decode()
+   can yield source coordinates outside the image (including negative
+   values) for perspective-distorted codes; converting such a value
+   directly to unsigned and using it to index img->data reads out of
+   bounds (CVE-2026-121942).  This mirrors the QR_CLAMPI() guard used by
+   qr_img_get_bit() in the QR decoder. */
+static unsigned sq_clamp_coord(float coord, unsigned dim)
+{
+    if (coord <= 0 || dim == 0)
+	return 0;
+    if (coord >= (float)(dim - 1))
+	return dim - 1;
+    return (unsigned)coord;
+}
+
 int _zbar_sq_decode(sq_reader *reader, zbar_image_scanner_t *iscn,
 		    zbar_image_t *img)
 {
@@ -548,12 +564,14 @@ found_start:;
 	    };
 
 	    const unsigned char *data = img->data;
-	    unsigned sample_x	      = top_left_source.x;
-	    unsigned sample_y	      = top_left_source.y;
+	    unsigned sample_x =
+		sq_clamp_coord(top_left_source.x, img->width);
+	    unsigned sample_y =
+		sq_clamp_coord(top_left_source.y, img->height);
 	    unsigned char top_left_color =
 		data[sample_y * img->width + sample_x];
-	    sample_x	       = bottom_right_source.x;
-	    sample_y	       = bottom_right_source.y;
+	    sample_x = sq_clamp_coord(bottom_right_source.x, img->width);
+	    sample_y = sq_clamp_coord(bottom_right_source.y, img->height);
 	    bottom_right_color = data[sample_y * img->width + sample_x];
 
 	    mixed_color =
Description: Bound SQ code sampling coordinates to the image (CVE-2026-121942)
 The SQ code decoder in _zbar_sq_decode() (zbar/sqcode.c) derives each pixel
 sample position by bilinear interpolation of the detected border-dot centres.
 For a perspective-distorted code those interpolated coordinates can fall
 outside the image, and a negative result additionally makes the following
 float-to-unsigned conversion undefined.  The raw value was used directly as
 an index into img->data, so a crafted grayscale (Y800) image with a skewed SQ
 finder pattern near an edge caused an out-of-bounds heap read (CWE-125),
 crashing the decoder and potentially leaking adjacent heap bytes into the
 decoded output.
 .
 Clamp both axes to [0, width-1] / [0, height-1] before indexing, mirroring the
 QR_CLAMPI() guard already used by qr_img_get_bit() in the QR decoder.  In-range
 coordinates are returned unchanged, so legitimate codes decode identically.
Author: Sumit Verma <[email protected]>
Bug: https://github.com/mchehab/zbar/issues/351
Bug-Debian: https://bugs.debian.org/1153258
Forwarded: no
Last-Update: 2026-11-06
--- a/zbar/sqcode.c
+++ b/zbar/sqcode.c
@@ -283,6 +283,22 @@
     return false;
 }
 
+/* Clamp a floating-point sample coordinate to a valid pixel index in
+   [0, dim - 1].  The SQ code border interpolation in _zbar_sq_decode()
+   can yield source coordinates outside the image (including negative
+   values) for perspective-distorted codes; converting such a value
+   directly to unsigned and using it to index img->data reads out of
+   bounds (CVE-2026-121942).  This mirrors the QR_CLAMPI() guard used by
+   qr_img_get_bit() in the QR decoder. */
+static unsigned sq_clamp_coord(float coord, unsigned dim)
+{
+    if (coord <= 0 || dim == 0)
+        return 0;
+    if (coord >= (float) (dim - 1))
+        return dim - 1;
+    return (unsigned) coord;
+}
+
 int _zbar_sq_decode (sq_reader *reader,
                      zbar_image_scanner_t *iscn,
                      zbar_image_t *img)
@@ -527,12 +543,12 @@
                 - right_border[border_len - 1].y};
 
             const unsigned char *data = img->data;
-            unsigned sample_x = top_left_source.x;
-            unsigned sample_y = top_left_source.y;
+            unsigned sample_x = sq_clamp_coord(top_left_source.x, img->width);
+            unsigned sample_y = sq_clamp_coord(top_left_source.y, img->height);
             unsigned char top_left_color =
                 data[sample_y * img->width + sample_x];
-            sample_x = bottom_right_source.x;
-            sample_y = bottom_right_source.y;
+            sample_x = sq_clamp_coord(bottom_right_source.x, img->width);
+            sample_y = sq_clamp_coord(bottom_right_source.y, img->height);
             unsigned char bottom_right_color =
                 data[sample_y * img->width + sample_x];
 

Reply via email to