Unverified Commit 5d760595 authored by 7c6f434c's avatar 7c6f434c Committed by GitHub
Browse files

zbar: patch out segfault from overoptimization on darwin (#459044)

parents 41465e63 d72ac2eb
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
From 3fa414aa82375648635281924904557cbe4d2d83 Mon Sep 17 00:00:00 2001
From: sasdf <asdf79852@gmail.com>
Date: Fri, 18 Oct 2024 00:22:36 +0800
Subject: [PATCH] Fix pointer wrap around undefined behavior

---
 zbar/img_scanner.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/zbar/img_scanner.c b/zbar/img_scanner.c
index d1bf8a3c..58436f16 100644
--- a/zbar/img_scanner.c
+++ b/zbar/img_scanner.c
@@ -33,6 +33,7 @@
 #endif
 
 #include <assert.h>
+#include <stddef.h>
 #include <stdlib.h> /* malloc, free */
 #include <string.h> /* memcmp, memset, memcpy */
 
@@ -50,7 +51,7 @@
 #include "svg.h"
 
 #if 1
-#define ASSERT_POS assert(p == data + x + y * (intptr_t)w)
+#define ASSERT_POS assert(p == data + x + y * (ptrdiff_t)w)
 #else
 #define ASSERT_POS
 #endif
@@ -858,11 +859,11 @@ static void zbar_send_code_via_dbus(zbar_image_scanner_t *iscn,
 }
 #endif
 
-#define movedelta(dx, dy)                \
-    do {                                 \
-	x += (dx);                       \
-	y += (dy);                       \
-	p += (dx) + ((uintptr_t)(dy)*w); \
+#define movedelta(dx, dy)                  \
+    do {                                   \
+        x += (dx);                         \
+        y += (dy);                         \
+        p += (dx) + ((dy)*(ptrdiff_t)(w)); \
     } while (0);
 
 static void *_zbar_scan_image(zbar_image_scanner_t *iscn, zbar_image_t *img)
+5 −0
Original line number Diff line number Diff line
@@ -62,6 +62,11 @@ stdenv.mkDerivation rec {
      url = "https://github.com/mchehab/zbar/commit/a549566ea11eb03622bd4458a1728ffe3f589163.patch";
      hash = "sha256-NY3bAElwNvGP9IR6JxUf62vbjx3hONrqu9pMSqaZcLY=";
    })
    # PR from fork not yet merged into upstream
    # See PR: https://github.com/mchehab/zbar/pull/299
    # Remove this patch if the PR is merged or if the issue is solved another way.
    # See https://github.com/NixOS/nixpkgs/issues/456461 for discussion of the root issue
    ./darwin-segfault-optimized-pointer-assignment.patch
  ];

  nativeBuildInputs = [