Jens Geyer created THRIFT-6256:
----------------------------------

             Summary: PHP: TTransport::readAll() loops forever when read() 
returns no bytes
                 Key: THRIFT-6256
                 URL: https://issues.apache.org/jira/browse/THRIFT-6256
             Project: Thrift
          Issue Type: Bug
          Components: PHP - Library
            Reporter: Jens Geyer


{{lib/php/lib/Transport/TTransport.php:56}}:

{code:php}
public function readAll(int $len): string
{
    $data = '';
    while (($got = strlen($data)) < $len) {
        $data .= $this->read($len - $got);
    }

    return $data;
}
{code}

The loop asks {{read()}} for the bytes it still needs and appends the result. A 
{{read()}} that returns an empty string appends nothing, and asking the same 
source again cannot change that, so the loop has no way to end. Nothing in 
{{lib/php}} returns an empty string from {{read()}} today -- the shipped 
transports raise {{TTransportException}} instead -- so this is not reachable as 
the library stands; it is a contract that any new or third-party transport can 
break silently.

c_glib had the same shape in {{thrift_transport_real_read_all()}} and it was 
given an explicit progress check.

h2. Suggested fix

Treat a zero-length read as the end of the stream and raise 
{{TTransportException(TTransportException::END_OF_FILE)}} rather than repeating 
a call that cannot advance.

The same loop exists in {{lib/perl/lib/Thrift/Transport.pm}} and 
{{lib/st/thrift.st}}; those are filed separately.

_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to