As an answer to https://github.com/llvm/llvm-project/issues/149, and to a comment in the code, syndicate base64 implementation between compiler-rt and clang-tools-extra
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/fuzzer/FuzzerUtil.cpp | ||
---|---|---|
14–16 | I don't believe we can do this. libfuzzer is acting as a sub-sub-project, |
As a side note, pre-reserving the buffer size gives interesting speedup, see http://quick-bench.com/Lp6OwO2etW1YEmJayVWn3U8JDiY
thanks for doing this! didn't look into details yet. Could you explain what was the bug in the previous code? since this patch contains some refactoring changes, it is not quite straightforward to spot it.
llvm/unittests/Support/Base64Test.cpp | ||
---|---|---|
2 | nit: Base64Test.cpp. | |
31 | nit: i would just inline the TestBase64. |
Yeah, the code was using + operator instead of | to combine the results, which is a problem when shifting signed values. (0xFF << 16) is implicitly converted to a (signed) int, and thus results in 0xffff0000, which is negative. Combining negative numbers with a + in that context is not what we want to do.
Add a test case that exhibits the overflow in previous implementation + minor nits from @hokein
llvm/unittests/Support/Base64Test.cpp | ||
---|---|---|
31 | I wouldn't :-) I find it easier to read like that, if that's okay with you. |
Looks like this change broke the UBSan build bots:
FAIL: LLVM-Unit :: Support/./SupportTests/Base64Test.Base64 (3484 of 36324) ******************** TEST 'LLVM-Unit :: Support/./SupportTests/Base64Test.Base64' FAILED ******************** Note: Google Test filter = Base64Test.Base64 [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from Base64Test [ RUN ] Base64Test.Base64 /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Base64.h:42:28: runtime error: left shift of negative value -1 #0 0x4993b6 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > llvm::encodeBase64<llvm::StringRef>(llvm::StringRef const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Base64.h:42:28 #1 0x498b78 in (anonymous namespace)::TestBase64(llvm::StringRef, llvm::StringRef) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/unittests/Support/Base64Test.cpp:23:14 #2 0x498aeb in Base64Test_Base64_Test::TestBody() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/unittests/Support/Base64Test.cpp:42:3 #3 0x8d85f9 in testing::Test::Run() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2474:5 #4 0x8d9581 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 #5 0x8d9f32 in testing::TestCase::Run() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 #6 0x8e1602 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 #7 0x8e1085 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:4257:10 #8 0x8d0933 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 #9 0x8d0933 in main /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50:10 #10 0x7f806f76e2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) #11 0x445d39 in _start (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/unittests/Support/SupportTests+0x445d39) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Base64.h:42:28 in ******************** Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Testing Time: 68.95s ******************** Failing Tests (1): LLVM-Unit :: Support/./SupportTests/Base64Test.Base64
I'll send out a revert shortly, to reproduce the sanitizer bots you can use the instructions here, or, given that this is UBSan, it should be sufficient to just add -DLLVM_USE_SANITIZER=Undefined and run check-llvm :).
I don't believe we can do this. libfuzzer is acting as a sub-sub-project,
and i strongly believe it wants to shy away from using anything
other than it's own headers and standard c/c++ headers.