Skip to content

binary_iarchive and binary_oarchive constructors crash in Visual Studio 2026 in Debug mode #389

Open

Description

@jmairboeck

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.

Activity

  1. jmairboeck commented on Nov 17, 2026

    @jmairboeck
    ContributorAuthor

    The problem only happens when linking boost_serialization statically, not with the DLL.

  2. robertramey commented on Nov 17, 2026

    @robertramey
    Member

    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.

  3. jmairboeck commented on Nov 18, 2026

    @jmairboeck
    ContributorAuthor

    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.

  4. added a commit that references this issue on Nov 18, 2026
    8a57cf6
  5. robertramey commented on Nov 18, 2026

    @robertramey
    Member

    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();
    }

  6. gennaroprota commented on Nov 19, 2026

    @gennaroprota
    Collaborator

    Hi Robert, did you see PR #390?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions