Skip to content

Commit 814f831

Browse files
committed
Fix for CVE-2019-20056, assertion failure problem(#126). Thanks to @sleicasper
1 parent 4fa442b commit 814f831

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/stb_image.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,13 +5045,13 @@ static int stbi__shiftsigned(int v, int shift, int bits)
50455045
static unsigned int shift_table[9] = {
50465046
0, 0,0,1,0,2,4,6,0,
50475047
};
5048+
if (bits < 0 || bits > 8) return (0); /* error */
50485049
if (shift < 0)
50495050
v <<= -shift;
50505051
else
50515052
v >>= shift;
5052-
STBI_ASSERT(v >= 0 && v < 256);
5053+
if (v < 0 || v >= 256) return (0);
50535054
v >>= (8-bits);
5054-
if (bits < 0 || bits > 8) return (0); /* error */
50555055
return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits];
50565056
}
50575057

0 commit comments

Comments
 (0)