AK: Utf8CodePointIterator: Don't output full string to debug output

When a code point is invalid, the full string was outputted to the debug
output. For large strings, this can make the system quite slow.
Furthermore, one of the cases incorrectly assumed the data to be null
terminated. This patch modifies the debug statements not to print the
full string.

This fixes oss-fuzz issue 35050.
This commit is contained in:
Max Wipfli 2021-06-08 15:19:09 +02:00 committed by Andreas Kling
parent efae7b7748
commit 3c7e775a9a
Notes: sideshowbarker 2024-07-18 12:37:22 +09:00

View file

@ -246,13 +246,13 @@ u32 Utf8CodePointIterator::operator*() const
if (!first_byte_makes_sense) {
// The first byte of the code point doesn't make sense: output a replacement character
dbgln("First byte doesn't make sense, bytes: {}", StringView { (const char*)m_ptr, m_length });
dbgln("First byte doesn't make sense: {:#02x}.", m_ptr[0]);
return 0xFFFD;
}
if (code_point_length_in_bytes > m_length) {
// There is not enough data left for the full code point: output a replacement character
dbgln("Not enough bytes (need {}, have {}), first byte is: {:#02x}, '{}'", code_point_length_in_bytes, m_length, m_ptr[0], (const char*)m_ptr);
dbgln("Not enough bytes (need {}, have {}), first byte is: {:#02x}.", code_point_length_in_bytes, m_length, m_ptr[0]);
return 0xFFFD;
}