Skip to content

Commit b2215f6

Browse files
committed
APItest/t/utf8_warn_base: Add tests
One UTF-8 malformation is when the string has a start byte in it before the expected end of the character. This test file tested the case where the unexpected byte came in the final position. GH #22597 found bugs where the unexpected byte came immediately after the first byte. This commit adds tests for unexpected bytes in all possible positions. If the fix for GH #22597 is reverted, this new revised file has 1400 failures.
1 parent 5718b26 commit b2215f6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ext/XS-APItest/t/utf8_warn_base.pl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,12 @@ ($)
11901190
# We try various combinations of malformations that can occur
11911191
foreach my $short (0, 1) {
11921192
next if $skip_most_tests && $short;
1193-
foreach my $unexpected_noncont (0, 1) {
1193+
# Insert an unexpected non-continuation in every possible position
1194+
my $unexpected_noncont;
1195+
for ($unexpected_noncont = $length - $short - 1;
1196+
$unexpected_noncont > 0;
1197+
$unexpected_noncont--)
1198+
{
11941199
next if $skip_most_tests && $unexpected_noncont;
11951200
foreach my $overlong (0, 1) {
11961201
next if $overlong && $skip_most_tests;
@@ -1318,11 +1323,14 @@ ($)
13181323

13191324
if ($unexpected_noncont) {
13201325

1321-
# To force this malformation, change the final continuation
1322-
# byte into a start byte.
1323-
my $pos = ($short) ? -2 : -1;
1324-
substr($this_bytes, $pos, 1) = $known_start_byte;
1325-
$this_expected_len--;
1326+
# The overlong tweaking above changes the first bytes to
1327+
# specified values; we better not override those.
1328+
next if $overlong;
1329+
1330+
# To force this malformation, change a continuation byte into a
1331+
# start byte.
1332+
substr($this_bytes, $unexpected_noncont, 1) = $known_start_byte;
1333+
$this_expected_len = $unexpected_noncont;
13261334
}
13271335

13281336
# The whole point of a test that is malformed from the beginning

0 commit comments

Comments
 (0)