-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
AddressSanitizer error when logging string longer than 250 chars. #2429
Comments
I think it is a problem with fmt library. |
Thank you for your reply. |
If the format is the cause, the following code would reproduce it. spdlog/include/spdlog/common.h Lines 151 to 154 in 6c95f4c
spdlog/include/spdlog/logger.h Lines 370 to 379 in 6c95f4c
using string_view_t = fmt::basic_string_view<char>;
string_view_t buf;
fmt::detail::vformat_to(buf,
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************{}" // 51
,
fmt::make_format_args("1"); |
BTW, the string formatted by spdlog should not contain |
thanks. I can't get the example to compile. I looked at fmts tests for vformat_to and the closets i can get to compile std::string s;
fmt::vformat_to(std::back_inserter(s),
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************{}" // 51
,
fmt::make_format_args("1")); Do you have inputs on compiling with string_view? |
Oh, I must be missing some fmt trick. |
Making sure we are talking about the same code :) std::string s;
fmt::vformat_to(std::back_inserter(s),
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************" // 50
"**************************************************{}" // 51
,
fmt::make_format_args("1")); |
I am not familiar with how to read AddressSanitizer reports, but isn't the heap-buffer-overflow caused by your If you are passing log messages to |
I think you are correct. I think it happens when I access payload.data(). If i do fmt::print("{}", msg.payload) then it works, but fmt::print("{}", msg.payload.data()) fails. |
Yes. You must pass |
great. Thank you for the help! I will close the issue. |
Thanks @tt4g ! |
When running the code below with sanitizer enabled i get a
==931743==ERROR: AddressSanitizer: heap-buffer-overflow
error.The error happens if the logged string is longer than 250 characters and has at least one fmt formatted argument. In the sanitize output there is some info about
0x16ceda1 in fmt::v8::basic_memory_buffer<char, 250ul, std::allocator<char> >::grow(unsigned long)
. Maybe the data that string_viewmsg.payload
is pointing to was moved when the buffer was grown?compiler: clang-13, ubuntu 20.04. spdlog 1.10.0
Minimal example
Sanitize output
The text was updated successfully, but these errors were encountered: