From 62b266ae4e2465ab24b5ed4761044e2af3015fee Mon Sep 17 00:00:00 2001
From: Petter Reinholdtsen <pere@debian.org>
Date: Sun, 9 Mar 2025 08:11:17 +0100
Subject: [PATCH] Made mask unsigned to avoid shifting into sign bit.

The last iteration of the loop execute 1<<63, which would push the
result into the signed bit of a signed 64 bit type, and this
move into currently undefined behaviour with C99.  Avoid the
issue by making the operation work on unsigned 64 bit type instead.

This require libogg version to 1.3.4, raise autotools dependency check
to look for this.

Partly solves github issue #18.
---
 configure.ac | 4 ++--
 lib/state.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 67506395..61b4cbdd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -392,7 +392,7 @@ dnl check for pkg-config itself so we don't try the m4 macro without pkg-config
 AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
 if test "x$HAVE_PKG_CONFIG" = "xyes"
 then
-  PKG_CHECK_MODULES(OGG, ogg >= 1.1, HAVE_OGG=yes, HAVE_OGG=no)
+  PKG_CHECK_MODULES(OGG, ogg >= 1.3.4, HAVE_OGG=yes, HAVE_OGG=no)
 fi
 if test "x$HAVE_OGG" = "xno"
 then
@@ -407,7 +407,7 @@ then
   CFLAGS="$CFLAGS $OGG_CFLAGS"
   LIBS="$LIBS $OGG_LIBS"
   AC_CHECK_FUNC(oggpackB_read, , [
-    AC_MSG_ERROR([newer libogg version (1.1 or later) required])
+    AC_MSG_ERROR([newer libogg version (1.3.4 or later) required])
   ])
   CFLAGS=$cflags_save
   LIBS=$libs_save
diff --git a/lib/state.c b/lib/state.c
index 8d8c22ea..77a7e133 100644
--- a/lib/state.c
+++ b/lib/state.c
@@ -388,7 +388,7 @@ static void oc_state_border_init(oc_theora_state *_state){
         /*Otherwise, check to see if it straddles the border.*/
         else if(x<crop_x0&&crop_x0<x+8||x<crop_xf&&crop_xf<x+8||
          y<crop_y0&&crop_y0<y+8||y<crop_yf&&crop_yf<y+8){
-          ogg_int64_t mask;
+          ogg_uint64_t mask;
           int         npixels;
           int         i;
           mask=npixels=0;
@@ -396,7 +396,7 @@ static void oc_state_border_init(oc_theora_state *_state){
             int j;
             for(j=0;j<8;j++){
               if(x+j>=crop_x0&&x+j<crop_xf&&y+i>=crop_y0&&y+i<crop_yf){
-                mask|=(ogg_int64_t)1<<(i<<3|j);
+                mask|=(ogg_uint64_t)1<<(i<<3|j);
                 npixels++;
               }
             }
-- 
GitLab