summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-01-04 21:52:59 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2023-01-04 22:00:25 -0500
commit9367ef1ed6b78d6bc078620009e383b3deae60b2 (patch)
tree49ba08351eca22982322f2cd063a99ef34ce2e92
parentea33e660211ea762e0ab4b820b500db1b0c91337 (diff)
downloadrockbox-9367ef1ed6b78d6bc078620009e383b3deae60b2.tar.gz
rockbox-9367ef1ed6b78d6bc078620009e383b3deae60b2.zip
[BugFix] Fix some Shif related UB -- ASAN
these are the low hanging fruit identified by ASAN cast the byte values before shift Change-Id: Ifc5645354a10c15ccd09d1343e1705857a51e011
-rw-r--r--firmware/export/pcm_sampr.h6
-rw-r--r--lib/rbcodec/codecs/libopus/ogg/framing.c5
-rw-r--r--lib/rbcodec/metadata/metadata_common.c27
3 files changed, 22 insertions, 16 deletions
diff --git a/firmware/export/pcm_sampr.h b/firmware/export/pcm_sampr.h
index 70f2dc2ba2..fc48a943fd 100644
--- a/firmware/export/pcm_sampr.h
+++ b/firmware/export/pcm_sampr.h
@@ -427,10 +427,10 @@ extern const unsigned long rec_freq_sampr[REC_NUM_FREQ];
427 427
428#ifdef CONFIG_SAMPR_TYPES 428#ifdef CONFIG_SAMPR_TYPES
429 429
430#define SAMPR_TYPE_MASK (0xff << 24) 430#define SAMPR_TYPE_MASK (0xffu << 24)
431#define SAMPR_TYPE_PLAY (0x00 << 24) 431#define SAMPR_TYPE_PLAY (0x00u << 24)
432#ifdef HAVE_RECORDING 432#ifdef HAVE_RECORDING
433#define SAMPR_TYPE_REC (0x01 << 24) 433#define SAMPR_TYPE_REC (0x01u << 24)
434#endif 434#endif
435 435
436#ifndef PCM_SAMPR_CONFIG_ONLY 436#ifndef PCM_SAMPR_CONFIG_ONLY
diff --git a/lib/rbcodec/codecs/libopus/ogg/framing.c b/lib/rbcodec/codecs/libopus/ogg/framing.c
index a7032a6a35..eb32351590 100644
--- a/lib/rbcodec/codecs/libopus/ogg/framing.c
+++ b/lib/rbcodec/codecs/libopus/ogg/framing.c
@@ -235,8 +235,9 @@ static int _os_lacing_expand(ogg_stream_state *os,long needed){
235 perform the checksum simultaneously with other copies */ 235 perform the checksum simultaneously with other copies */
236 236
237static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int size){ 237static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int size){
238 #define u32(v) (uint32_t)v
238 while (size>=8){ 239 while (size>=8){
239 crc^=buffer[0]<<24|buffer[1]<<16|buffer[2]<<8|buffer[3]; 240 crc^=((u32(buffer[0]))<<24)|((u32(buffer[1]))<<16)|((u32(buffer[2]))<<8)|(u32(buffer[3]));
240 241
241 crc=crc_lookup[7][ crc>>24 ]^crc_lookup[6][(crc>>16)&0xFF]^ 242 crc=crc_lookup[7][ crc>>24 ]^crc_lookup[6][(crc>>16)&0xFF]^
242 crc_lookup[5][(crc>> 8)&0xFF]^crc_lookup[4][ crc &0xFF]^ 243 crc_lookup[5][(crc>> 8)&0xFF]^crc_lookup[4][ crc &0xFF]^
@@ -246,7 +247,7 @@ static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int
246 buffer+=8; 247 buffer+=8;
247 size-=8; 248 size-=8;
248 } 249 }
249 250 #undef u32
250 while (size--) 251 while (size--)
251 crc=(crc<<8)^crc_lookup[0][((crc >> 24)&0xff)^*buffer++]; 252 crc=(crc<<8)^crc_lookup[0][((crc >> 24)&0xff)^*buffer++];
252 return crc; 253 return crc;
diff --git a/lib/rbcodec/metadata/metadata_common.c b/lib/rbcodec/metadata/metadata_common.c
index 8eec16a877..f051c94e2c 100644
--- a/lib/rbcodec/metadata/metadata_common.c
+++ b/lib/rbcodec/metadata/metadata_common.c
@@ -148,17 +148,20 @@ int read_uint64le(int fd, uint64_t* buf)
148uint64_t get_uint64_le(void* buf) 148uint64_t get_uint64_le(void* buf)
149{ 149{
150 unsigned char* p = (unsigned char*) buf; 150 unsigned char* p = (unsigned char*) buf;
151 151 #define u64(v) (uint64_t)v
152 return ((uint64_t)p[0]) | ((uint64_t)p[1] << 8) | ((uint64_t)p[2] << 16) | ((uint64_t)p[3] << 24) | ((uint64_t)p[4] << 32) | 152 return (u64(p[0])) | ((u64(p[1])) << 8) | ((u64(p[2])) << 16)
153 ((uint64_t)p[5] << 40) | ((uint64_t)p[6] << 48) | ((uint64_t)p[7] << 56); 153 | ((u64(p[3])) << 24) | ((u64(p[4])) << 32) |((u64(p[5])) << 40)
154 | ((u64(p[6])) << 48) | ((u64(p[7])) << 56);
155 #undef u64
154} 156}
155 157
156/* Read an unaligned 32-bit little endian long from buffer. */ 158/* Read an unaligned 32-bit little endian long from buffer. */
157uint32_t get_long_le(void* buf) 159uint32_t get_long_le(void* buf)
158{ 160{
159 unsigned char* p = (unsigned char*) buf; 161 unsigned char* p = (unsigned char*) buf;
160 162 #define u32(v) (uint32_t)v
161 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); 163 return (u32(p[0])) | ((u32(p[1])) << 8) | ((u32(p[2])) << 16) | ((u32(p[3])) << 24);
164 #undef u32
162} 165}
163 166
164/* Read an unaligned 16-bit little endian short from buffer. */ 167/* Read an unaligned 16-bit little endian short from buffer. */
@@ -166,15 +169,16 @@ uint16_t get_short_le(void* buf)
166{ 169{
167 unsigned char* p = (unsigned char*) buf; 170 unsigned char* p = (unsigned char*) buf;
168 171
169 return p[0] | (p[1] << 8); 172 return ((uint16_t)p[0]) | (((uint16_t)p[1]) << 8);
170} 173}
171 174
172/* Read an unaligned 32-bit big endian long from buffer. */ 175/* Read an unaligned 32-bit big endian long from buffer. */
173uint32_t get_long_be(void* buf) 176uint32_t get_long_be(void* buf)
174{ 177{
175 unsigned char* p = (unsigned char*) buf; 178 unsigned char* p = (unsigned char*) buf;
176 179 #define u32(v) (uint32_t)v
177 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 180 return ((u32(p[0])) << 24) | ((u32(p[1])) << 16) | ((u32(p)[2]) << 8) | (u32(p[3]));
181 #undef u32
178} 182}
179 183
180/* Read an unaligned 16-bit little endian short from buffer. */ 184/* Read an unaligned 16-bit little endian short from buffer. */
@@ -182,15 +186,16 @@ uint16_t get_short_be(void* buf)
182{ 186{
183 unsigned char* p = (unsigned char*) buf; 187 unsigned char* p = (unsigned char*) buf;
184 188
185 return (p[0] << 8) | p[1]; 189 return (((uint16_t)p[0]) << 8) | ((uint16_t)p[1]);
186} 190}
187 191
188/* Read an unaligned 32-bit little endian long from buffer. */ 192/* Read an unaligned 32-bit little endian long from buffer. */
189int32_t get_slong(void* buf) 193int32_t get_slong(void* buf)
190{ 194{
191 unsigned char* p = (unsigned char*) buf; 195 unsigned char* p = (unsigned char*) buf;
192 196 #define i32(v) (int32_t)v
193 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); 197 return (i32(p[0])) | ((i32(p[1])) << 8) | ((i32(p[2])) << 16) | ((i32(p[3])) << 24);
198 #undef i32
194} 199}
195 200
196uint32_t get_itunes_int32(char* value, int count) 201uint32_t get_itunes_int32(char* value, int count)