Problem description
When downloading files with the S3CrtClient, write errors to the Aws::Iostream body are ignored (not even logged).
This silent failure is problematic, in particular when using a TransferManager, since it requires external validation to check the transfer.
The problem is that the failbit/badbit are not checked after write/flush:
// generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp
int S3CrtClient::S3CrtRequestGetBodyCallback(struct aws_s3_meta_request *meta_request, const struct aws_byte_cursor *body, uint64_t range_start, void *user_data)
{
AWS_UNREFERENCED_PARAM(range_start);
auto *userData = static_cast<S3CrtClient::CrtRequestCallbackUserData*>(user_data);
if (!userData || !userData->response || !userData->request) {
return AWS_OP_ERR;
}
auto& bodyStream = userData->response->GetResponseBody();
bodyStream.write(reinterpret_cast<char*>(body->ptr), static_cast<std::streamsize>(body->len));
if (userData->request->IsEventStreamRequest())
{
bodyStream.flush();
}
// Continues here without checking for errors.
// ...
}
We realized this while testing downloads in parallel where one of the downloads ran into a streambuf error.
What to do
Check bodyStream.fail() and if true, return AWS_OP_ERR, logging the cause of the error.
AWS CPP SDK version used
Problem is present on main.
Compiler and Version used
clang >= 15
Operating System and version
ubuntu 22.x
Problem description
When downloading files with the
S3CrtClient, write errors to theAws::Iostreambody are ignored (not even logged).This silent failure is problematic, in particular when using a
TransferManager, since it requires external validation to check the transfer.The problem is that the
failbit/badbitare not checked afterwrite/flush:We realized this while testing downloads in parallel where one of the downloads ran into a
streambuferror.What to do
Check
bodyStream.fail()and iftrue, returnAWS_OP_ERR, logging the cause of the error.AWS CPP SDK version used
Problem is present on
main.Compiler and Version used
clang >= 15
Operating System and version
ubuntu 22.x