Cut Unicode ill-formed byte sweeps to one representative prefix

Wrong-2nd and wrong-3rd-byte sections iterated every valid trailing
byte, which dominated Linux --no-skip runtime without testing extra
properties. Pin those bytes to a single valid continuation.

The fourth-byte typo is left to #5416 so this change stands alone.

Signed-off-by: elix3r <157088510+22elix3r@users.noreply.github.com>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
elix3r
2026-09-27 21:44:47 +02:00
committed by Niels Lohmann
parent 373005f7ac
commit c6bb0844f3
3 changed files with 65 additions and 85 deletions
+23 -32
View File
@@ -250,49 +250,40 @@ TEST_CASE("Unicode (5/5)" * doctest::skip())
SECTION("ill-formed: wrong second byte")
{
for (int byte1 = 0xF4; byte1 <= 0xF4; ++byte1)
// Pin later continuation bytes (#5418). F4's valid 2nd byte
// range is 0x80-0x8F.
const int byte1 = 0xF4;
const int byte3 = 0x80;
const int byte4 = 0x80;
for (int byte2 = 0x00; byte2 <= 0xFF; ++byte2)
{
for (int byte2 = 0x00; byte2 <= 0xFF; ++byte2)
// skip correct second byte
if (0x80 <= byte2 && byte2 <= 0x8F)
{
// skip correct second byte
if (0x80 <= byte2 && byte2 <= 0x8F)
{
continue;
}
for (int byte3 = 0x80; byte3 <= 0xBF; ++byte3)
{
for (int byte4 = 0x80; byte4 <= 0xBF; ++byte4)
{
check_utf8string(false, byte1, byte2, byte3, byte4);
check_utf8dump(false, byte1, byte2, byte3, byte4);
}
}
continue;
}
check_utf8string(false, byte1, byte2, byte3, byte4);
check_utf8dump(false, byte1, byte2, byte3, byte4);
}
}
SECTION("ill-formed: wrong third byte")
{
for (int byte1 = 0xF4; byte1 <= 0xF4; ++byte1)
// Pin 2nd/4th bytes to one valid continuation (#5418).
const int byte1 = 0xF4;
const int byte2 = 0x80;
const int byte4 = 0x80;
for (int byte3 = 0x00; byte3 <= 0xFF; ++byte3)
{
for (int byte2 = 0x80; byte2 <= 0x8F; ++byte2)
// skip correct third byte
if (0x80 <= byte3 && byte3 <= 0xBF)
{
for (int byte3 = 0x00; byte3 <= 0xFF; ++byte3)
{
// skip correct third byte
if (0x80 <= byte3 && byte3 <= 0xBF)
{
continue;
}
for (int byte4 = 0x80; byte4 <= 0xBF; ++byte4)
{
check_utf8string(false, byte1, byte2, byte3, byte4);
check_utf8dump(false, byte1, byte2, byte3, byte4);
}
}
continue;
}
check_utf8string(false, byte1, byte2, byte3, byte4);
check_utf8dump(false, byte1, byte2, byte3, byte4);
}
}