forked from Mirrors/openclonk
IsValidUtf8: Obey string length parameter when checking continuation bytes
This fixes a bug where sequences were incorrectly accepted when they ended with a multibyte sequence, the end of which was beyond the passed string length.
parent
1ba02a610b
commit
02416caec5
|
@ -867,6 +867,11 @@ bool IsValidUtf8(const char *text, int length)
|
|||
// Standard 7-bit ASCII value (i.e., 1 byte codepoint)
|
||||
continue;
|
||||
}
|
||||
else if (length >= 0 && cursor - input + continuation_bytes >= length)
|
||||
{
|
||||
// Too few remaining bytes
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute character value, so we can detect overlong sequences
|
||||
assert((*cursor & 0xC0) == 0xC0);
|
||||
|
|
Loading…
Reference in New Issue