Skip to content

Commit 5f2587e

Browse files
committed
php-fuzz-mbstring also tests text encoding validation functions
In 6fc8d01, pakutoma added specialized validation functions for ISO-2022-JP, JIS, UTF-7, and UTF7-IMAP text. In the future, it is possible we might add such functions for more legacy text encodings. Allowing them to be tested by php-fuzz-mbstring may help to catch bugs, both now and in the future.
1 parent 6ec69d7 commit 5f2587e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sapi/fuzzer/fuzzer-mbstring.c

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
103103
assert_zend_string_eql(Result1, Result2);
104104
ZEND_ASSERT(errors1 == errors2);
105105

106+
/* For some text encodings, we have specialized validation functions. These should always be
107+
* stricter than the conversion functions; if the conversion function receives invalid input
108+
* and emits an error marker (MBFL_BAD_INPUT), then the validation function should always
109+
* return false. However, if the conversion function does not emit any error marker, it may
110+
* still happen in some cases that the validation function returns false. */
111+
if (FromEncoding->check != NULL) {
112+
bool good = FromEncoding->check((unsigned char*)Data, Size);
113+
if (errors1 > 0) {
114+
ZEND_ASSERT(!good);
115+
}
116+
}
117+
106118
zend_string_release(Result1);
107119
zend_string_release(Result2);
108120
efree(ToEncodingName);

0 commit comments

Comments
 (0)