Skip to content

Commit

Permalink
app-arch/bzip2: fix an error reported by ubsan
Browse files Browse the repository at this point in the history
Use unsigned 1 for shifting instead of signed 1.

Fix an issue with shift caught by undefined behavior
sanitizer in clang.
bzip2-1.0.6/blocksort.c:255:7
runtime error: left shift of 1 by 31 places cannot be represented
in type 'int'.

Closes: gentoo#9688
Signed-off-by: Thomas Deutschmann <[email protected]>
  • Loading branch information
m-gupta authored and Whissi committed Aug 24, 2018
1 parent b56fc08 commit 66f614c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ PATCHES=(
"${FILESDIR}"/${PN}-1.0.6-mingw.patch #393573
"${FILESDIR}"/${PN}-1.0.6-out-of-tree-build.patch
"${FILESDIR}"/${PN}-1.0.6-CVE-2016-3189.patch #620466
"${FILESDIR}"/${PN}-1.0.6-ubsan-error.patch
)

DOCS=( CHANGES README{,.COMPILATION.PROBLEMS,.XML.STUFF} manual.pdf )
Expand Down
24 changes: 24 additions & 0 deletions app-arch/bzip2/files/bzip2-1.0.6-ubsan-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Author: Manoj Gupta <[email protected]>

Use unsigned 1 for shifting instead of signed 1.

This fixed an issue with shift caught by undefined behavior
sanitizer in clang.
bzip2-1.0.6/blocksort.c:255:7
runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

--- a/blocksort.c
+++ b/blocksort.c
@@ -202,9 +202,9 @@ void fallbackQSort3 ( UInt32* fmap,
bhtab [ 0 .. 2+(nblock/32) ] destroyed
*/

-#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31))
-#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31))
-#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31)))
+#define SET_BH(zz) bhtab[(zz) >> 5] |= (1u << ((zz) & 31))
+#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1u << ((zz) & 31))
+#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1u << ((zz) & 31)))
#define WORD_BH(zz) bhtab[(zz) >> 5]
#define UNALIGNED_BH(zz) ((zz) & 0x01f)

0 comments on commit 66f614c

Please sign in to comment.