Skip to content

Commit 175b438

Browse files
committed
Fix spurious failures of php-fuzz-mbstring
1 parent f1bc43b commit 175b438

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sapi/fuzzer/fuzzer-mbstring.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
111111
if (FromEncoding->check != NULL) {
112112
bool good = FromEncoding->check((unsigned char*)Data, Size);
113113
if (errors1 > 0) {
114-
ZEND_ASSERT(!good);
114+
/* If the conversion function emits an error marker, that may or may not mean the input
115+
* was invalid; it could also be that the input was valid, but it contains codepoints
116+
* which cannot be represented in the output encoding.
117+
* To confirm if that is the case, try converting to UTF-8, which can represent any
118+
* Unicode codepoint. */
119+
unsigned int errors3 = 0;
120+
zend_string *Temp = convert_encoding(Data, Size, FromEncoding, &mbfl_encoding_utf8, 128, &errors3);
121+
if (errors3 > 0) {
122+
ZEND_ASSERT(!good);
123+
}
124+
zend_string_release(Temp);
115125
}
116126
}
117127

0 commit comments

Comments
 (0)