Jens Geyer created THRIFT-6222:
----------------------------------
Summary: D: the HTTP transport returns a truncated body without an
error when the connection ends early
Key: THRIFT-6222
URL: https://issues.apache.org/jira/browse/THRIFT-6222
Project: Thrift
Issue Type: Bug
Components: D - Library
Reporter: Jens Geyer
h2. What happens
When the peer closes the connection before it has sent the {{Content-Length}}
it declared, the D HTTP transport hands back the part that arrived as if the
body were complete, and the protocol goes on to decode a truncated message.
h2. Why
{{readContent()}} in {{lib/d/src/thrift/transport/http.d}}:
{code}
while (need > 0) {
if (httpBufRemaining_.length == 0) {
httpBufRemaining_ = httpBuf_[0 .. 0];
if (!refill()) return size - need;
}
...
}
{code}
A failed {{refill()}} returns the count read so far, and the caller only treats
{{0}} as the end of the stream. The C++ {{THttpTransport}}, which this
transport follows, throws {{TTransportException(END_OF_FILE)}} from
{{refill()}} in the same situation.
A unittest in {{http.d}} currently pins the short return, so the boundary is
visible.
h2. Suggested fix
Throw {{END_OF_FILE}} when the stream ends before the declared length has been
read, and change that unittest to expect it.
_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)