From f0356612d923bf31a9760b7e50ded1a6d9f47112 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 6 May 2024 09:49:41 +0300 Subject: [PATCH] Fix undefined behavior (left shift of negative number) Fixes oss-fuzz #68722 --- ext/standard/image.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/standard/image.c b/ext/standard/image.c index d5455963f31..d064d9d4fd3 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -749,10 +749,10 @@ static signed short php_ifd_get16s(void *Short, int motorola_intel) static int php_ifd_get32s(void *Long, int motorola_intel) { if (motorola_intel) { - return ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16) - | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 ); + return ((unsigned)((( char *)Long)[0]) << 24) | (((unsigned char *)Long)[1] << 16) + | ((( char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 ); } else { - return ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16) + return ((unsigned)((( char *)Long)[3]) << 24) | (((unsigned char *)Long)[2] << 16) | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 ); } }