Repository navigation
Open
Description
The following simple test program crashes when building it with Visual Studio 2026 (18.12, MSVC 14.52) in Debug mode, using the official binaries of Boost 1.92.0.
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
auto serialize() -> std::string {
std::ostringstream os;
boost::archive::binary_oarchive a{ os };
return os.str();
}
void deserialize(const std::string& data) {
std::istringstream is { data };
boost::archive::binary_iarchive a{ is };
}
int main()
{
std::string str = serialize();
//std::ifstream file{ "test.bin", std::ios::binary };
//file >> str;
std::cout << str << std::endl;
std::ofstream file{ "test.bin", std::ios::binary };
file << str;
file.close();
//deserialize(str);
}Stack trace from the debugger:
[Ausnahme ausgelöst bei 0x00007FFF9887F1A8 (msvcp140d.dll) in ConsoleApplication1.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFFFFFFFFFFFFFFFF.]
msvcp140d.dll!std::basic_streambuf<char,std::char_traits<char>>::sputn(const char * _Ptr, __int64 _Count) Zeile 171 C++
ConsoleApplication1.exe!boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive,char,std::char_traits<char>>::save_binary(const void * address, unsigned __int64 count) Zeile 167 C++
ConsoleApplication1.exe!boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive,char,std::char_traits<char>>::save<unsigned __int64>(const unsigned __int64 & t) Zeile 90 C++
ConsoleApplication1.exe!boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive,char,std::char_traits<char>>::save(const std::string & s) Zeile 70 C++
ConsoleApplication1.exe!boost::archive::save_access::save_primitive<boost::archive::binary_oarchive,std::string>(boost::archive::binary_oarchive & ar, const std::string & t) Zeile 95 C++
ConsoleApplication1.exe!boost::archive::detail::save_non_pointer_type<boost::archive::binary_oarchive>::save_primitive::invoke<std::string>(boost::archive::binary_oarchive & ar, const std::string & t) Zeile 239 C++
ConsoleApplication1.exe!boost::archive::detail::save_non_pointer_type<boost::archive::binary_oarchive>::invoke<std::string>(boost::archive::binary_oarchive & ar, const std::string & t) Zeile 317 C++
ConsoleApplication1.exe!boost::archive::save<boost::archive::binary_oarchive,std::string const>(boost::archive::binary_oarchive & ar, const std::string & t) Zeile 541 C++
ConsoleApplication1.exe!boost::archive::detail::common_oarchive<boost::archive::binary_oarchive>::save_override<std::string const>(const std::string & t) Zeile 71 C++
ConsoleApplication1.exe!boost::archive::basic_binary_oarchive<boost::archive::binary_oarchive>::save_override<std::string>(const std::string & t) Zeile 80 C++
ConsoleApplication1.exe!boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive,char,std::char_traits<char>>::save_override<std::string const>(const std::string & t) Zeile 59 C++
ConsoleApplication1.exe!boost::archive::detail::interface_oarchive<boost::archive::binary_oarchive>::operator<<<std::string>(const std::string & t) Zeile 71 C++
ConsoleApplication1.exe!boost::archive::basic_binary_oarchive<boost::archive::binary_oarchive>::init() Zeile 37 C++
ConsoleApplication1.exe!boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive,char,std::char_traits<char>>::init(unsigned int flags) Zeile 66 C++
ConsoleApplication1.exe!boost::archive::binary_oarchive::binary_oarchive(std::basic_ostream<char,std::char_traits<char>> & os, unsigned int flags) Zeile 46 C++
ConsoleApplication1.exe!serialize() Zeile 66 C++
ConsoleApplication1.exe!main() Zeile 78 C++
ConsoleApplication1.exe!invoke_main() Zeile 79 C++
ConsoleApplication1.exe!__scrt_common_main_seh() Zeile 288 C++
ConsoleApplication1.exe!__scrt_common_main() Zeile 331 C++
ConsoleApplication1.exe!mainCRTStartup(void * __formal) Zeile 17 C++
kernel32.dll!BaseThreadInitThunk() Unbekannt
ntdll.dll!RtlUserThreadStart() Unbekannt
The error message is an access violation ("this" was "0xFFFFFFFFFFFFFFFF") in sputn.
In Release mode, everything works as it should.
Metadata
Metadata
Assignees
Labels
No labels
Activity
jmairboeck commentedon Nov 17, 2026
The problem only happens when linking boost_serialization statically, not with the DLL.
robertramey commentedon Nov 17, 2026
I'm going to confess that I'm absolutely mystified by the code in this test.
auto serialize() -> std::string {
std::ostringstream os;
boost::archive::binary_oarchive a{ os };
return os.str();
}
Is this meant to be equivalent to the following?
std::string serialize() {
std::ostringstream os;
boost::archive::binary_oarchive a{ os };
return os.str();
}
It looks like the binary_archive contains a public function named "str()" whose value is returned from the function. I have no idea what that value might be or where it comes from. There is no such function in the Archve Concept. Even assuming it there were, what value would it return? What is the test expected to display. I'm lost here. I'm sure that the problem is the latest C++ syntax is now beyond me.
jmairboeck commentedon Nov 18, 2026
Yes, this just constructs a binary_oarchive (named
a) from an ostringstream (os) and returns the resulting string without serializing anything. str() is a member function of the ostringstream. Serializing an object is not necessary for the test because the constructor already crashes when trying to write the file signature.Work around MSVC 14.52 converting to empty bases with the wrong offset
robertramey commentedon Nov 18, 2026
OK - found std::ostrsream in cppreference [https://en.cppreference.com/cpp/io/ostrstream] . Not that it's important here it says deprecated in C++98 and removed in C++26.
I'm strongly suspecting that this is not a serialization ilbrary issue but an issue with the io library. I don't have a C++ compilation system at hand. Maybe you can help me out a little here. Does the following code exhibit the same problem? If so, we could let the serialization library off the hook. Let me know. Thanks for helping me out here.
auto serialize() -> std::string {
std::ostringstream os;
// boost::archive::binary_oarchive a{ os };
return os.str();
}
gennaroprota commentedon Nov 19, 2026
Hi Robert, did you see PR #390?