rnpgp / rnp

RNP: high performance C++ OpenPGP library used by Mozilla Thunderbird
https://www.rnpgp.org
Other
194 stars 55 forks source link

OSS-Fuzz build broken: error: static_assert failed due to requirement '__is_cpp17_move_insertable #1249

Closed tomrittervg closed 4 years ago

tomrittervg commented 4 years ago

The OSS-Fuzz build is breaking, since Aug 4th. Normally they file a breakage bug, I'm not sure why they didn't this time, I filed https://github.com/google/oss-fuzz/issues/4278 to ask.

The error is:

[ 11%] Building CXX object src/lib/CMakeFiles/librnp-obj.dir/__/librepgp/stream-key.cpp.o
cd /src/rnp-build/src/lib && /usr/local/bin/clang++ -D_GNU_SOURCE -Dlibrnp_EXPORTS -I/src/rnp-build/src/lib -I/src/rnp/src/common -I/src/rnp/include -I/src/rnp/src/lib -I/src/rnp/src -isystem /usr/include/botan-2 -isystem /usr/include/json-c -O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -stdlib=libc++ -O3 -DNDEBUG -fPIC -fvisibility=hidden -Wall -Wextra -Wunreachable-code -Wpointer-arith -Wmissing-declarations -Wno-pedantic -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-missing-field-initializers -std=c++11 -o CMakeFiles/librnp-obj.dir/__/librepgp/stream-key.cpp.o -c /src/rnp/src/librepgp/stream-key.cpp
In file included from /src/rnp/src/librepgp/stream-key.cpp:36:
In file included from /src/rnp/src/librepgp/stream-key.h:33:
In file included from /src/rnp/include/rnp.h:35:
In file included from /src/rnp/src/lib/types.h:55:
In file included from /usr/local/bin/../include/c++/v1/string:506:
In file included from /usr/local/bin/../include/c++/v1/string_view:175:
In file included from /usr/local/bin/../include/c++/v1/__string:57:
In file included from /usr/local/bin/../include/c++/v1/algorithm:643:
/usr/local/bin/../include/c++/v1/memory:1634:13: error: static_assert failed due to requirement '__is_cpp17_move_insertable<std::__1::allocator<pgp_transferable_userid_t>, false>::value' "The specified type does not meet the requirements of Cpp17MoveInsertable"
            static_assert(__is_cpp17_move_insertable<allocator_type>::value,
            ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/bin/../include/c++/v1/vector:954:21: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<pgp_transferable_userid_t>>::__construct_backward_with_exception_guarantees<pgp_transferable_userid_t *>' requested here
    __alloc_traits::__construct_backward_with_exception_guarantees(
                    ^
/usr/local/bin/../include/c++/v1/vector:1672:5: note: in instantiation of member function 'std::__1::vector<pgp_transferable_userid_t, std::__1::allocator<pgp_transferable_userid_t>>::__swap_out_circular_buffer' requested here
    __swap_out_circular_buffer(__v);
    ^
/usr/local/bin/../include/c++/v1/vector:1690:9: note: in instantiation of function template specialization 'std::__1::vector<pgp_transferable_userid_t, std::__1::allocator<pgp_transferable_userid_t>>::__emplace_back_slow_path<const pgp_transferable_userid_t &>' requested here
        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
        ^
/src/rnp/src/librepgp/stream-key.cpp:197:25: note: in instantiation of function template specialization 'std::__1::vector<pgp_transferable_userid_t, std::__1::allocator<pgp_transferable_userid_t>>::emplace_back<const pgp_transferable_userid_t &>' requested here
            dst.userids.emplace_back(srcuid);
                        ^
1 error generated.

The problem is that when compiling with clang, it uses gcc's libc++ by default. However in the oss-fuzz container, they specify -stdlib=libc++ as a compile flag; which causes llvm's libc++ to be used, and hit this static assert.

I couldn't reproduce this using clang-6 in my docker container, so I just matched the llvm version used in oss-fuzz via roughly this process in a docker container:

git clone https://github.com/llvm/llvm-project.git
cd  llvm-project
git checkout 1bd7046e4ce0102adef6096a12a289d7f94b8c73
cd ..
mkdir llvm-build && cd llvm-build
cmake -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;libcxx;libcxxabi;compiler-rt;lld' -DCMAKE_INSTALL_PREFIX=/llvm ../llvm
cmake --build .
cmake --install .
cd ..
cd rnp-build
cmake -DENABLE_SANITIZERS=1 -DENABLE_FUZZERS=1 -DCMAKE_C_COMPILER=/llvm/bin/clang -DCMAKE_CXX_COMPILER=/llvm/bin/clang++ -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=on -DBUILD_TESTING=off -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ../rnp/
// Build will succeed. Grab the build command for stream-key.cpp then add `-stdlib=libc++`

I know that is kind of annoying. If you throw a patch up you think will fix the issue I can test it.

ni4 commented 4 years ago

@tomrittervg Thanks for spending your time one investigating this. It should be definitely related to #1244 and looks like the easiest way to solve it (despite it is not reflected in CI yet) is to implement move constructor for pgp_transferable_userid_t. I'll make a PR soon.

ni4 commented 4 years ago

@tomrittervg Could you please quick-check whether this PR fixes an issue: https://github.com/rnpgp/rnp/pull/1250/files ?

tomrittervg commented 4 years ago

@ni4 It does!

ni4 commented 4 years ago

@tomrittervg Great, thanks for confirming!

ni4 commented 4 years ago

Closing this since issue is fixed.