1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Add tests to document behavior of UTF7-IMAP conversion in obscure corner case

These unit tests cover situations which were not previously tested by the
mbstring test suite. Adding them will make the test suite more complete.

To be specific, the 'obscure' case which we are now testing is: what happens
when the first half of a surrogate pair appears at end of an improperly
terminated Base64 section in UTF7-IMAP text?
This commit is contained in:
Alex Dowad
2023-07-16 15:19:19 +02:00
parent a57fdea149
commit 9aa4b2bbad

View File

@@ -147,9 +147,17 @@ identifyInvalidString("&" . mBase64($doubleChar . $testString) . "-", 'UTF7-IMAP
/* 3. The first half of a surrogate pair could come at the end of the string, */
$testString = mb_convert_encoding("\x00\x01\x04\x00", 'UTF-16BE', 'UTF-32BE');
identifyInvalidString("&" . mBase64(substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
identifyInvalidString("&" . mBase64($singleChar . substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
identifyInvalidString("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
testInvalid("&" . mBase64(substr($testString, 0, 2)) . "-", "%");
testInvalid("&" . mBase64($singleChar . substr($testString, 0, 2)) . "-", "\x01%");
testInvalid("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)) . "-", "\x01\x01%");
/* ...and the string could even be improperly terminated... */
testInvalid("&" . mBase64(substr($testString, 0, 2)), "%%");
testInvalid("&" . mBase64($singleChar . substr($testString, 0, 2)), "\x01%%");
/* NOTE: We currently don't check for trailing first half of surrogate pair when the string
* abruptly ends after a group of 3 Base64-encoded codepoints... that's why we only emit one
* error marker here for the incorrect termination of Base64 section and no error marker
* for the trailing first half of surrogate pair */
testInvalid("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)), "\x01\x01%");
/* 4. Or, it could have an odd number of bytes in it! */
$testString = utf16BE("ドーナツ");