STL icon indicating copy to clipboard operation
STL copied to clipboard

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

Open frederick-vs-ja opened this issue 2 years ago • 0 comments

Describe the bug

Currently, MSVC STL's basic_stringbuf relies on that the eback() pointer points to the beginning of the allocated buffer. https://github.com/microsoft/STL/blob/e077eb66871626d93f50d329e8fa19cefa80aeb3/stl/inc/sstream#L495-L497

Likewise, basic_syncbuf requires pbase() to behave the same way. https://github.com/microsoft/STL/blob/e077eb66871626d93f50d329e8fa19cefa80aeb3/stl/inc/syncstream#L247

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

https://github.com/microsoft/STL/blob/e077eb66871626d93f50d329e8fa19cefa80aeb3/tests/libcxx/expected_results.txt#L1103-L1107

Expected behavior

These tests pass.

STL version

https://github.com/microsoft/STL/commit/e077eb66871626d93f50d329e8fa19cefa80aeb3

(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.

frederick-vs-ja avatar Dec 16 '23 01:12 frederick-vs-ja