mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Fix undefined behavior in STREAM buffer bounds checking by avoiding out-of-bounds pointer arithmetic
This commit is contained in:
parent
3185e1bf34
commit
608393867a
2 changed files with 4 additions and 3 deletions
|
|
@ -277,7 +277,7 @@ int sdeplete(STREAM* s, unsigned char* last)
|
|||
|
||||
while (1) {
|
||||
/* increase the position up to 4 bytes before the end */
|
||||
if (s->pos + 4 <= s->end)
|
||||
if (s->end - s->pos >= 4)
|
||||
s->pos = s->end - 4;
|
||||
|
||||
/* insert the last 4 bytes */
|
||||
|
|
|
|||
|
|
@ -152,9 +152,10 @@ uint32_t scrc_stream(STREAM* s);
|
|||
/**
|
||||
* Check if the buffer has enough data loaded.
|
||||
*/
|
||||
static inline int sptrlookup(STREAM* s, ssize_t size)
|
||||
static inline int sptrlookup(STREAM* s, size_t size)
|
||||
{
|
||||
return s->pos + size <= s->end;
|
||||
/* compute remaining distance to avoid pointer arithmetic out of buffer bounds */
|
||||
return size <= (size_t)(s->end - s->pos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue