Add checks for invalid UTF-8 sequences, see: https://svn.boost.org/trac/boost/ticket/9473

This commit is contained in:
jzmaddock
2013-12-19 10:45:50 +00:00
parent 0983ff065e
commit f1aa75af2c
5 changed files with 56 additions and 2 deletions

View File

@ -629,9 +629,15 @@ private:
0x1FFFFFu,
};
m_value &= masks[extra];
// check the result:
// check the result is in range:
if(m_value > static_cast<U32Type>(0x10FFFFu))
invalid_sequence();
// The result must not be a surrogate:
if((m_value >= static_cast<U32Type>(0xD800)) && (m_value <= static_cast<U32Type>(0xDFFF)))
invalid_sequence();
// We should not have had an invalidly encoded UTF8 sequence:
if((extra > 0) && (m_value <= static_cast<U32Type>(masks[extra - 1])))
invalid_sequence();
}
BaseIterator m_position;
mutable U32Type m_value;