Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined behavior when using async_write_some and write_some with large buffers #1443

Open
ashtum opened this issue Mar 7, 2024 · 0 comments

Comments

@ashtum
Copy link

ashtum commented Mar 7, 2024

It seems that the limit of the buffer size allowed to pass to async_write_some and write_some is platform-dependent and undocumented.

For example, on Windows, a narrowing conversion in this line:

return bytes_transferred;

causes incorrect reports of the number of written bytes when the buffer size is >= 2^31:

std::string buf(2'147'483'648, '*'); // a buffer of up to 2'147'483'647 bytes would be just fine
auto bytes_transferred = socket.write_some(asio::buffer(buf));
assert(bytes_transferred == 0); // reports 0 while all 2'147'483'648 bytes are written successfully 

The same issue occurs for async_write_some when the buffer size is >= 2^32:

std::string buf(4'294'967'296, '*'); // a buffer of up to 4'294'967'295 bytes would be just fine
auto bytes_transferred = co_await socket.async_write_some(asio::buffer(buf), asio::deferred);
assert(bytes_transferred == 0); // reports 0 while all 4'294'967'296 bytes are written successfully 

Because these types of limitations are platform-dependent, the expected behavior might be that async_write_some and write_some internally limit the buffer size instead of exhibiting surprising or undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant