boostorg / boostorg/iostreams

boost::iostreams::stream<boost::iostreams::array> fails for size > 2GB when calling tellp

Open
#164 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
48
Forks
124
PR merge metrics
No merged PRs in 30d

Description

Test program:
```c++
#include
#include
#include
#include
#include
#include

int main(int argc, char* argv[])
{
// some numbers such that total buffer is larger than 2GB
const std::streamoff s1(2000);
const std::streamoff s2(314748);
std::vector buffer(s1*s2);
const auto buf_size = static_cast(buffer.size())* sizeof(float);
typedef boost::iostreams::stream array_stream;
array_stream s(reinterpret_cast(buffer.data()), buf_size);

// write some data from a smaller buffer
std::vector buffer2(s2, 1.F);
for (std::streamoff i=0; i(buffer2.data()), s2*sizeof(float));
}
if (std::abs(buffer[s1*s2-1] -1.F) > .001F)
{
std::cerr << "wrong output\n";
return 1;
}
return 0;
}
```
fails. g++-8 and boost 1.65.1 gives
```
...
before (1704) 2145322368
before (1705) 2146581360
before (1706) -1
before (1707) -1
...
wrong output
```
g++-12 and boost 1.74.0. gives
```
...
before (1704) 2145322368
before (1705) 2146581360
terminate called after throwing an instance of 'boost::wrapexcept'
what(): bad seek: iostream error
Aborted (core dumped)
```
It works fine when not calling `tellg()`. This is similar to https://github.com/boostorg/interprocess/issues/190, although here we don't have a segfault.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by compiling and running the supplied C++ reproducer with boost::iostreams::stream, including the tellp calls after the position exceeds 2GB. Trace the array stream's position handling around that boundary. Done means large-buffer writes complete, tellp continues returning valid positions, and the final buffer check succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.