Skip to content
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

<sstream>, <syncstream>: Buffer types assume that allocated pointers are not modified by users #4268

Open
frederick-vs-ja opened this issue Dec 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Dec 16, 2023

Describe the bug

Currently, MSVC STL's basic_stringbuf relies on that the eback() pointer points to the beginning of the allocated buffer.

STL/stl/inc/sstream

Lines 495 to 497 in e077eb6

_Al.deallocate(_Ptr_traits::pointer_to(*_Mysb::eback()),
static_cast<typename allocator_traits<allocator_type>::size_type>(
(_Mysb::pptr() ? _Mysb::epptr() : _Mysb::egptr()) - _Mysb::eback()));

Likewise, basic_syncbuf requires pbase() to behave the same way.

_Getal().deallocate(_Refancy<_Pointer>(streambuf_type::pbase()), _Buf_size);

However, the pointers returned by these functions can be modified by users via setg/setp functions, which means these conditions can't be considered as invariants maintained by the implementation.

Command-line test case

# Not analyzed. Assertion failed: _CrtIsValidHeapPointer(block)
std/input.output/string.streams/stringbuf/stringbuf.members/str.pass.cpp FAIL
std/input.output/string.streams/stringbuf/stringbuf.members/view.pass.cpp FAIL
std/input.output/syncstream/syncbuf/syncstream.syncbuf.cons/dtor.pass.cpp FAIL
std/input.output/syncstream/syncbuf/syncstream.syncbuf.members/emit.pass.cpp FAIL

Expected behavior

These tests pass.

STL version

e077eb6

(Probably in all versions where basic_stringbuf or basic_syncbuf is available.)

Additional context

Not sure whether this can be fixed without breaking ABI. #4239 may be related, but doesn't fix any part of this issue.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jan 10, 2024
@StephanTLavavej StephanTLavavej changed the title <sstream>, <syncstream>: Buffer types rely on that pointers modificable by users point to the beginning of the allocated buffer <sstream>, <syncstream>: Buffer types assume that allocated pointers are not modified by users Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants