4 * "UTF-8" (actually "WTF-8") to UTF-16LE (actually "arbitrary sequence of
5 * 16-bit wchars") and back again should be lossless, unless the initial string
6 * isn't valid WTF-8, in which case WIMLIB_ERR_INVALID_UTF8_STRING is expected.
9 fuzz_utf8_roundtrip(const u8 *in, size_t insize)
17 ret = wimlib_utf8_to_utf16le((const char *)in, insize,
20 assert(ret == WIMLIB_ERR_INVALID_UTF8_STRING);
24 ret = wimlib_utf16le_to_utf8(utf16, utf16_size, &result, &result_size);
26 assert(result_size == insize);
27 assert(memcmp(result, in, insize) == 0);
33 * "UTF-16LE" (actually "arbitrary sequence of 16-bit wchars") to UTF-8
34 * (actually "WTF-8") and back again should be lossless, unless the initial
35 * length isn't a multiple of 2 bytes, in which case
36 * WIMLIB_ERR_INVALID_UTF16_STRING is expected.
39 fuzz_utf16_roundtrip(const u8 *in, size_t insize)
41 utf16lechar *in_aligned = malloc(insize);
48 memcpy(in_aligned, in, insize);
49 ret = wimlib_utf16le_to_utf8(in_aligned, insize, &utf8, &utf8_size);
51 assert(ret == WIMLIB_ERR_INVALID_UTF16_STRING);
56 ret = wimlib_utf8_to_utf16le(utf8, utf8_size, &result, &result_size);
58 assert(result_size == insize);
59 assert(memcmp(result, in, insize) == 0);
65 /* Fuzz character encoding conversion. */
66 int LLVMFuzzerTestOneInput(const u8 *in, size_t insize)
76 fuzz_utf8_roundtrip(in, insize);
79 fuzz_utf16_roundtrip(in, insize);