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.
Nicolas Hake 2011-05-17 17:55:27 +02:00
parent 1ba02a610b
commit 02416caec5
1 changed files with 5 additions and 0 deletions

View File

@ -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);