-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.85] flat_map/vector crashes on appends (memory corruption) #273
Comments
Bisect shows that the first bad commit is 1a4a205. Reverting this commit on 1.85 (with resolved conflicts) fixes the crash. |
Thanks for the report! I think the issue is produced because flat_map used UB in the implementation, long ago, when C++03 compilers had no movable std::pair type and the class was designed to achieve move emulation in those compilers. The following commit should fix the issue, your example seems to work after the commit, but I didn't want to close the issue without having your feedback: |
Thanks, the commit does fix the problem. It is probably worth attaching this patch to the 1.85.0 release notes. |
Closing this issue as fixed. |
@igaztanaga How come this was not caught by a unit test? |
I think it was optimization-level and context code (inlining decisions) dependent and Boost.Container tests only failed consistently with latest GCC versions (>=11, I think). MSVC and clang showed no failure. Once latest GCC versions were mainstream, boost.Container tests were failing and I figure out that UB could be the cause. |
FYI Similar bug (UB => #include <boost/container/flat_map.hpp>
struct A {
int i;
auto operator<=>(const A&) const = default;
};
int main() {
boost::container::flat_map<A, A> map;
map.emplace(A{1}, A{});
for (auto const& [_1, _2] : map)
throw 123; // this line is never executed, UB!
} Might be worth getting a patch posted on https://www.boost.org/patches/ and https://www.boost.org/users/history/version_1_85_0.html as a known issue (e.g. how it was done for the 1.83.0 and earlier releases). E: So, fun. This wasn't caught internally to my org because
|
Does boost-1.86.0-beta1 include the fix for this? |
Yes. Release notes were not updated for this beta but the fix is there. |
Trying to build a patch for 1.85 I could not reproduce the bug with Boost.Build. It turns out that Build defines -DNDEBUG and that avoids @Lastique's example's crash... Anyway, here's the first patch for 1.85 if you want to test it: |
The patch is better placed on the website and linked in 1.85 release notes. See an example of a PR doing this here. |
Many thanks for your example Andrey. PR: |
Drop LCG 104. LCG 106 ships with Boost 1.85.0 which has a known UB issue (boostorg/container#273) that causes the vertexing to fail.
Consider this test code:
This crashes with:
valgrind
also shows a number of invalid memory accesses, see the attached log:test_flat_map.log
This code works correctly in Boost 1.84.0. It also doesn't crash if compiled with
-O0
.gcc 11.4.0, Kubuntu 22.04.
The text was updated successfully, but these errors were encountered: