aws / aws/aws-sdk-cpp

CurlHttpClient: tellp() failure in CurlHttpClient::WriteData with Boost filtering_stream

Open
#3,364 4 comments 0 reactions 1 assignee Claimed by @SergeyRyabinin View on GitHub
bug feature-request investigating
Dominant language
C++
Stars
2.2k
Forks
1.2k
Avg merge
3d 14h
Merged PRs (30d)
12

Description

### Describe the bug

**Root Cause**:
When using `CurlHttpClient::WriteData` with a `boost::iostreams::filtering_stream` (e.g., compression/decompression filters), the call to `response->GetResponseBody().tellp()` fails and logs:

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

This is expected behavior since boost::iostreams::filtering_stream with compression/decompression filters doesn't fully support the tellp() operation due to the non-linear nature of the data transformation.

### Current Behavior

**Detail**:
I've encountered an issue in the AWS SDK(1.1.496) C++ code related to the use of tellp() in the CurlHttpClient::WriteData function.

When the response body is a boost::iostreams::filtering_stream (particularly with compression/decompression filters), the following code fails with an error:

```cpp
auto cur = response->GetResponseBody().tellp();
if (response->GetResponseBody().fail()) {
const auto& ref = response->GetResponseBody();
AWS_LOGSTREAM_ERROR(CURL_HTTP_CLIENT_TAG, "Unable to query response output position (eof: "
<< ref.eof() << ", bad: " << ref.bad() << ")");
return 0;
}

The error log shows: "Unable to query response output position (eof: 0, bad: 1)"

### Reproduction Steps

**Reproduction Steps**

1. Create a response body stream using `boost::iostreams::filtering_stream` with compression filters:
```cpp
#include
#include
#include

void ReproduceTellpFailure() {
// Create a response with boost filtering_stream
auto response = Aws::MakeShared(
"TestResponse", Aws::Http::HttpRequest{}
);

// Setup compressed response stream
boost::iostreams::filtering_ostream decompression_stream;
decompression_stream.push(boost::iostreams::gzip_decompressor()); // Problematic filter
decompression_stream.push(response->GetResponseBody()); // Connect to AWS response stream

response->SetResponseBody(decompression_stream);

// Simulate data write (typical usage pattern)
decompression_stream.write("TestData", 8);
decompression_stream.flush();

// Trigger the tellp() check
auto position = response->GetResponseBody().tellp(); // << Fails here
}

### Possible Solution

It will be possible to modify this code to check if the stream supports tellp() before attempting to use it, or use an alternative approach for tracking position? For example:

Use try/catch to handle unsupported tellp() operation
Skip position tracking for certain stream types
Use the existing m_numBytesResponseReceived counter instead of tellp()
This would improve compatibility with clients that use filtering_stream for compressed content handling.

Thank you for your consideration.

### Additional Information/Context

_No response_

### AWS CPP SDK version used

v1.11.496

### Compiler and Version used

gcc: 9.4.0

### Operating System and version

ubuntu20.04

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.