mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-21 15:36:33 -05:00
Fix binary varint decoders to reject values overflowing uint32_t/uint64_t declared widths
This commit is contained in:
parent
acacfc1fbc
commit
7ccb243a79
2 changed files with 99 additions and 4 deletions
|
|
@ -586,7 +586,7 @@ int sgetb32(STREAM* f, uint32_t* value)
|
|||
{
|
||||
uint32_t v;
|
||||
unsigned char b;
|
||||
unsigned char s;
|
||||
unsigned s;
|
||||
int c;
|
||||
|
||||
v = 0;
|
||||
|
|
@ -603,7 +603,7 @@ loop:
|
|||
if ((b & 0x80) == 0) {
|
||||
v |= (uint32_t)b << s;
|
||||
s += 7;
|
||||
if (s >= 32) {
|
||||
if (tommy_unlikely(s >= 32)) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -611,6 +611,13 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for overflow: at s == 28 only 4 bits (0x0f) fit in uint32_t
|
||||
*/
|
||||
if (tommy_unlikely(s == 28 && (b & 0x70) != 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
v |= (uint32_t)(b & 0x7f) << s;
|
||||
|
||||
*value = v;
|
||||
|
|
@ -622,7 +629,7 @@ int sgetb64(STREAM* f, uint64_t* value)
|
|||
{
|
||||
uint64_t v;
|
||||
unsigned char b;
|
||||
unsigned char s;
|
||||
unsigned s;
|
||||
int c;
|
||||
|
||||
v = 0;
|
||||
|
|
@ -639,7 +646,7 @@ loop:
|
|||
if ((b & 0x80) == 0) {
|
||||
v |= (uint64_t)b << s;
|
||||
s += 7;
|
||||
if (s >= 64) {
|
||||
if (tommy_unlikely(s >= 64)) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -647,6 +654,13 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for overflow: at s == 63 only 1 bit (0x01) fits in uint64_t
|
||||
*/
|
||||
if (tommy_unlikely(s == 63 && (b & 0x7e) != 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
v |= (uint64_t)(b & 0x7f) << s;
|
||||
|
||||
*value = v;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue