mirror of
https://gitlab.freedesktop.org/uchardet/uchardet.git
synced 2025-12-06 16:56:40 +08:00
Issue #32: Global buffer read overflow in GetOrderFromCodePoint.
This commit is contained in:
parent
bd983ca108
commit
bc93da89d9
@ -247,31 +247,26 @@ const char* nsLanguageDetector::GetLanguage()
|
|||||||
|
|
||||||
int nsLanguageDetector::GetOrderFromCodePoint(int codePoint)
|
int nsLanguageDetector::GetOrderFromCodePoint(int codePoint)
|
||||||
{
|
{
|
||||||
int max = mModel->charOrderTableSize;
|
int min = 0;
|
||||||
|
int max = mModel->charOrderTableSize - 1;
|
||||||
int i = max / 2;
|
int i = max / 2;
|
||||||
int c = mModel->charOrderTable[i * 2];
|
int c;
|
||||||
|
|
||||||
while ((c = mModel->charOrderTable[i * 2]) != codePoint)
|
while ((c = mModel->charOrderTable[i * 2]) != codePoint)
|
||||||
{
|
{
|
||||||
if (c > codePoint)
|
if (c > codePoint)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == min)
|
||||||
break;
|
break;
|
||||||
max = i - 1;
|
max = i - 1;
|
||||||
i = i / 2;
|
|
||||||
}
|
|
||||||
else if (i < max - 1)
|
|
||||||
{
|
|
||||||
i += (max - i) / 2;
|
|
||||||
}
|
|
||||||
else if (i == max - 1)
|
|
||||||
{
|
|
||||||
i = max;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (i == max)
|
||||||
break;
|
break;
|
||||||
|
min = i + 1;
|
||||||
}
|
}
|
||||||
|
i = min + (max - min) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (c == codePoint) ? mModel->charOrderTable[i * 2 + 1] : -1;
|
return (c == codePoint) ? mModel->charOrderTable[i * 2 + 1] : -1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user