Subject: [Boost-bugs] [Boost C++ Libraries] #12383: boost::asio fails to read more than 65536 bytes from file asyncronously
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-08-09 07:10:22
#12383: boost::asio fails to read more than 65536 bytes from file asyncronously
------------------------------+----------------------------
Reporter: AStepanjuk@⦠| Owner: chris_kohlhoff
Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
Version: Boost 1.61.0 | Severity: Problem
Keywords: |
------------------------------+----------------------------
When more than `65536` bytes are read into a buffer from a file using
`boost::asio::windows::stream_handle` asynchronously, then buffer contains
the wrong data after reading is completed.
Starting from `65537`th byte the buffer contains the the data from the
very beginning of the file, rather than the expected data.
Here is a code example, which reproduces the issue:
{{{
auto handle = ::CreateFile(L"BigFile.xml", GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
boost::asio::io_service ios;
boost::asio::windows::stream_handle streamHandle(ios, handle);
const auto to_read_bytes = 100000;
char buffer[to_read_bytes];
boost::asio::async_read(streamHandle, boost::asio::buffer(buffer,
to_read_bytes), [](auto &ec, auto read) {
std::cout << "Bytes read: " << read << std::endl;
});
ios.run();
auto bufferBegin = std::string(buffer, 38);
auto bufferCorrupted = std::string(buffer + 65536, 38); // <- it
contains bytes from the beginning of the file
std::cout << "offset 0: " << bufferBegin << std::endl;
std::cout << "offset 65536: " << bufferCorrupted << std::endl;
::CloseHandle(handle);
}}}
That code produces an output:
> `Bytes read: 100000` [[br]]
> `offset 0: <?xml version="1.0" encoding="UTF-8"?>` [[br]]
> `offset 65536: <?xml version="1.0" encoding="UTF-8"?>` [[br]]
The source file is a valid XML file, which is bigger than 65536 bytes in
size.
This is reproducible with boost 1.61 + VS2015. Also that issue was in
boost 1.55 + VS2010. [[br]]
Operating systems are: Windows 7 and Windows Server 2008R2.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12383> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC