microsoft / microsoft/STL

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

Open
#4,268 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.