Skip to content

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

Description

@KrisThielemans

Test program:

#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream.hpp>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <cmath>

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<float> buffer(s1*s2);
  const auto buf_size = static_cast<std::streamsize>(buffer.size())* sizeof(float);
  typedef boost::iostreams::stream<boost::iostreams::array> array_stream;
  array_stream s(reinterpret_cast<char *>(buffer.data()), buf_size);

  // write some data from a smaller buffer
  std::vector<float> buffer2(s2, 1.F);
  for (std::streamoff i=0; i<s1; ++i)
    {
      std::cout << "before (" << i << ") " << s.tellp() << std::endl;
      s.write(reinterpret_cast<const char *>(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<std::ios_base::failure[abi:cxx11]>'
  what():  bad seek: iostream error
Aborted (core dumped)

It works fine when not calling tellg(). This is similar to boostorg/interprocess#190, although here we don't have a segfault.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions