From 02416caec5e5fb55a14bac8aadc3deff524b0fda Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Tue, 17 May 2011 17:55:27 +0200 Subject: [PATCH] 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. --- src/lib/Standard.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/Standard.cpp b/src/lib/Standard.cpp index cd79564df..31503a25c 100644 --- a/src/lib/Standard.cpp +++ b/src/lib/Standard.cpp @@ -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);