Boost C++ Libraries: Ticket #12383: boost::asio fails to read more than 65536 bytes from file asyncronously https://svn.boost.org/trac10/ticket/12383 <p> When more than <code>65536</code> bytes are read into a buffer from a file using <code>boost::asio::windows::stream_handle</code> asynchronously, then buffer contains the wrong data after reading is completed. </p> <p> Starting from <code>65537</code>th byte the buffer contains the the data from the very beginning of the file, rather than the expected data. </p> <p> Here is a code example, which reproduces the issue: </p> <pre class="wiki">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 &amp;ec, auto read) { std::cout &lt;&lt; "Bytes read: " &lt;&lt; read &lt;&lt; std::endl; }); ios.run(); auto bufferBegin = std::string(buffer, 38); auto bufferCorrupted = std::string(buffer + 65536, 38); // &lt;- it contains bytes from the beginning of the file std::cout &lt;&lt; "offset 0: " &lt;&lt; bufferBegin &lt;&lt; std::endl; std::cout &lt;&lt; "offset 65536: " &lt;&lt; bufferCorrupted &lt;&lt; std::endl; ::CloseHandle(handle); </pre><p> That code produces an output: </p> <blockquote class="citation"> <p> <code>Bytes read: 100000</code> <br /> <code>offset 0: &lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> <br /> <code>offset 65536: &lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> <br /> </p> </blockquote> <p> The source file is a valid XML file, which is bigger than 65536 bytes in size. </p> <p> 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. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12383 Trac 1.4.3 AStepanjuk@… Wed, 10 Aug 2016 10:46:28 GMT <link>https://svn.boost.org/trac10/ticket/12383#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12383#comment:1</guid> <description> <p> The solution for the issue and much more other details, including the reason of it, could be found in answers to my question on stackoverflow: <a class="ext-link" href="http://stackoverflow.com/questions/38833771/boostasio-fails-to-read-more-than-65536-bytes-from-file"><span class="icon">​</span>http://stackoverflow.com/questions/38833771/boostasio-fails-to-read-more-than-65536-bytes-from-file</a> </p> <p> I still think, it's a defect. At least such limitation in 65536 bytes should be mentioned in the documentation for <code>boost::asio::windows::stream_handle</code> </p> </description> <category>Ticket</category> </item> </channel> </rss>