`<sstream>`, `<syncstream>`: Buffer types assume that allocated pointers are not modified by users
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
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
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the referenced implementations in stl/inc/sstream and stl/inc/syncstream, then review the command-line test case and its entry in tests/libcxx/expected_results.txt. Determine how user-modified eback() and pbase() pointers affect the existing assumptions, while checking the ABI concern noted in the issue. Done means the linked tests pass without relying on those pointers remaining unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100