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
+25 -32
View File
@@ -250,49 +250,42 @@ TEST_CASE("Unicode (3/5)" * doctest::skip())
SECTION("ill-formed: wrong second byte")
{
for (int byte1 = 0xF0; byte1 <= 0xF0; ++byte1)
// Property: an out-of-range 2nd byte is rejected regardless of
// later continuation bytes. Pin those to one valid value so
// this section does not sweep 192*64*64 combinations (#5418).
const int byte1 = 0xF0;
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 (0x90 <= byte2 && byte2 <= 0xBF)
{
// skip correct second byte
if (0x90 <= byte2 && byte2 <= 0xBF)
{
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 = 0xF0; byte1 <= 0xF0; ++byte1)
// Property: an out-of-range 3rd byte is rejected regardless of
// the 2nd/4th bytes. Pin those to one valid value (#5418).
const int byte1 = 0xF0;
const int byte2 = 0x90;
const int byte4 = 0x80;
for (int byte3 = 0x00; byte3 <= 0xFF; ++byte3)
{
for (int byte2 = 0x90; byte2 <= 0xBF; ++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);
}
}