Gif decoder: fix read error caused by ub check

The recently added check to avoid negative-bitshift ub ignored that
the algorithm will sometimes use a negative bitcount value as a
flag. This caused reading failure for some frames.

Pick-to: 5.15 5.12
Fixes: QTBUG-86702
Change-Id: I4c247a7eb6102f9b51cc8ac708c60db80d609e38
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Eirik Aavitsland 2020-09-18 14:55:32 +02:00
parent 2cbeacd2cd
commit f1c1f44481
1 changed files with 7 additions and 5 deletions

View File

@ -492,12 +492,14 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length,
break;
case ImageDataBlock:
count++;
if (bitcount < 0 || bitcount > 31) {
state = Error;
return -1;
if (bitcount != -32768) {
if (bitcount < 0 || bitcount > 31) {
state = Error;
return -1;
}
accum |= (ch << bitcount);
bitcount += 8;
}
accum|=(ch<<bitcount);
bitcount+=8;
while (bitcount>=code_size && state==ImageDataBlock) {
int code=accum&((1<<code_size)-1);
bitcount-=code_size;