diff --git a/pkgs/tools/graphics/zbar/darwin-segfault-optimized-pointer-assignment.patch b/pkgs/tools/graphics/zbar/darwin-segfault-optimized-pointer-assignment.patch new file mode 100644 index 000000000000..ebf38552cbde --- /dev/null +++ b/pkgs/tools/graphics/zbar/darwin-segfault-optimized-pointer-assignment.patch @@ -0,0 +1,47 @@ +From 3fa414aa82375648635281924904557cbe4d2d83 Mon Sep 17 00:00:00 2001 +From: sasdf +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 ++#include + #include /* malloc, free */ + #include /* 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) diff --git a/pkgs/tools/graphics/zbar/default.nix b/pkgs/tools/graphics/zbar/default.nix index 8d77795366a2..58b64c4fd1a1 100644 --- a/pkgs/tools/graphics/zbar/default.nix +++ b/pkgs/tools/graphics/zbar/default.nix @@ -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 = [