Skip to content

Commit

Permalink
Fuzzing harness for fbjni utf16toUTF8
Browse files Browse the repository at this point in the history
Summary: Project Sierra showed a crash in this code. While we don't know exactly how its used its worth putting up a fuzzer for it.

Reviewed By: alichtman

Differential Revision: D47807803

fbshipit-source-id: b4ca1383f0d87f628bc1124068b994c27ee14d53
  • Loading branch information
calvano-fb authored and facebook-github-bot committed Jul 31, 2023
1 parent 66fa297 commit 070e640
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/jni/utf16toUTF8_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <fbjni/detail/utf8.h>

#include <security/lionhead/utils/lib_ftest/ftest.h>

using namespace std;
using namespace facebook::jni;

Expand Down Expand Up @@ -49,7 +51,22 @@ TEST(Utf16toUTF8_test, goodUtf16String) {
EXPECT_EQ(utf8String, "a\xC4\xA3\xE1\x88\xB4\xF0\x94\xA0\xB4");
}

FUZZ(Utf16toUTF8_test, fuzz_utf16toUTF8) {
try {
auto utf16String = f.bytes("utf16string");
if (utf16String.empty() || utf16String.size() % 2 != 0) {
return;
}
auto utf8String = detail::utf16toUTF8(
(uint16_t*)utf16String.data(), utf16String.size() / 2);
(void)utf8String;
} catch (...) {
}
}

#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#endif

0 comments on commit 070e640

Please sign in to comment.