Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UTF-8 decoder more restrictive #712

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/libFLAC/bitreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading