Make UTF-8 decoder more restrictive (#712)

Fixes https://github.com/xiph/flac/issues/706
This commit is contained in:
Martijn van Beurden 2024-07-03 09:10:30 +02:00 committed by GitHub
parent b773157a59
commit b6b5b3259f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 11 deletions

View File

@ -939,23 +939,23 @@ FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *v
v = x;
i = 0;
}
else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
else if((x & 0xE0) == 0xC0) { /* 110xxxxx */
v = x & 0x1F;
i = 1;
}
else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
else if((x & 0xF0) == 0xE0) { /* 1110xxxx */
v = x & 0x0F;
i = 2;
}
else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
else if((x & 0xF8) == 0xF0) { /* 11110xxx */
v = x & 0x07;
i = 3;
}
else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
else if((x & 0xFC) == 0xF8) { /* 111110xx */
v = x & 0x03;
i = 4;
}
else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
else if((x & 0xFE) == 0xFC) { /* 1111110x */
v = x & 0x01;
i = 5;
}
@ -994,27 +994,27 @@ FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *v
v = x;
i = 0;
}
else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
else if((x & 0xE0) == 0xC0) { /* 110xxxxx */
v = x & 0x1F;
i = 1;
}
else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
else if((x & 0xF0) == 0xE0) { /* 1110xxxx */
v = x & 0x0F;
i = 2;
}
else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
else if((x & 0xF8) == 0xF0) { /* 11110xxx */
v = x & 0x07;
i = 3;
}
else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
else if((x & 0xFC) == 0xF8) { /* 111110xx */
v = x & 0x03;
i = 4;
}
else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
else if((x & 0xFE) == 0xFC) { /* 1111110x */
v = x & 0x01;
i = 5;
}
else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
else if(x == 0xFE) { /* 11111110 */
v = 0;
i = 6;
}