diff mercurial/bitmanipulation.h @ 38303:1fb2510cf8c8

bitmanipulation: fix undefined behavior in bit shift in getbe32 OSS-Fuzz caught this in its ubsan mode[0]. I'm not worried about a security issue here because in practice this should work out the way we naively expected, we're just making things explicit to the compiler with the casts. 0: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8876 Differential Revision: https://phab.mercurial-scm.org/D3729
author Augie Fackler <augie@google.com>
date Wed, 13 Jun 2018 10:24:44 -0400
parents ce77b0563228
children eed42f1c22d6
line wrap: on
line diff
--- a/mercurial/bitmanipulation.h	Wed Jun 13 21:58:42 2018 +0900
+++ b/mercurial/bitmanipulation.h	Wed Jun 13 10:24:44 2018 -0400
@@ -9,7 +9,8 @@
 {
 	const unsigned char *d = (const unsigned char *)c;
 
-	return ((d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]));
+	return ((((uint32_t)d[0]) << 24) | (((uint32_t)d[1]) << 16) |
+	        (((uint32_t)d[2]) << 8) | (d[3]));
 }
 
 static inline int16_t getbeint16(const char *c)