#11699 closed Bugs (fixed)
Forward declarations of std templates causes stack corruption under Visual Studio 2015
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | interprocess |
Version: | Boost 1.59.0 | Severity: | Problem |
Keywords: | Cc: |
Description
In Visual Studio 2015 it can lead to stack corruption if I instantiate std::basic_istream with the same types in two compilation units, and one of them forward declares the template and the other doesn't.
I originally run into this problem when I called a funtion in a library that called boost::lexical_cast. The source file containing the function included a header from interprocess, which included interprocess/detail/std_fwd.hpp which contains a forward declaration of std::basic_istream.
Unfortunately std::basic_istream was also instatiated with the same types in my main program (but there was no forward declaration).
I presume this can happen with other templates as well, but so far this is the only one I found.
The same code was working fine with Visual Studio 2013.
I created two small solutions:
- BoostStackCorruption_VS2015: using boost::lexical_cast and an interprocess header
- StdStackCorruption_VS2015: using only std but with lines coming from the insides of lexical_cast and interprocess/detail/std_fwd.hpp
Attachments (2)
Change History (7)
by , 7 years ago
Attachment: | StdStackCorruption_VS2015.zip added |
---|
comment:1 by , 7 years ago
Thanks for the report. It seems that it is a compiler bug, and standard libraries before Visual 2013 used some dummy virtual functions in basic_istream and basic_ostream to fix it. Starting with Visual 2013 <istream> and <ostream> contain a pragma to fix the bug with the comment:
#pragma vtordisp(push, 2) // compiler bug workaround
The fix is to use the same pragma when forward declaring the basic_istream and basic_ostream.
Thanks a lot for the detailed report and MSVC solutions, they helped a lot.
comment:2 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in develop branch, soon to be merged to master. Commit:
https://github.com/boostorg/interprocess/commit/845d352287902b535b75b5545ff448744fa79820
comment:3 by , 7 years ago
Thanks for the fast fix.
Does that mean that only std::basic_istream and std::basic_ostream are affected? Can we be sure that all the other forward declarations of templates in std used by boost are safe?
comment:4 by , 7 years ago
Those are the only classes in the MSVC STL that are marked with that bug-fixing pragma. It's related to virtual inheritance, and only ios classes use that type of inheritance. We can't be 100% sure, but I'm pretty confident about that.
Stack corruption with std only