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

Update unicoder.cpp #1584

Merged
merged 1 commit into from
Nov 24, 2022
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
13 changes: 6 additions & 7 deletions Src/Common/unicoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,18 +1134,19 @@ bool CheckForInvalidUtf8(const char* pBuffer, size_t size)
for (unsigned char* pb = (unsigned char*)pBuffer, *end = pb + size; pb < end;)
{
unsigned c = *pb++;
if ((c == 0xC0) || (c == 0xC1) || (c >= 0xF5))
return true;


if (!(c & 0x80)) continue;

if ((c >= 0xF5) || (c == 0xC0) || (c == 0xC1))
return true;

uint32_t v = 0x80808080;
uint32_t v = 0x80808000; //1st 0-byte covers scenario if no any next "if" fired at all

if ((c & 0xE0) == 0xC0)
{
if (pb == end)
return true;
reinterpret_cast<unsigned char*>(&v)[0] = *pb++;
*reinterpret_cast<unsigned char*>(&v) = *pb++;
}
else if ((c & 0xF0) == 0xE0)
{
Expand All @@ -1164,8 +1165,6 @@ bool CheckForInvalidUtf8(const char* pBuffer, size_t size)
reinterpret_cast<uint8_t*>(&v)[2] = pb[2];
pb += 3;
}
else
return true;

if ((v & (0xC0C0C0C0)) != 0x80808080)
return true;
Expand Down