Jens Geyer created THRIFT-6257:
----------------------------------
Summary: Perl: Thrift::Transport::readAll() loops forever when
read() returns no bytes
Key: THRIFT-6257
URL: https://issues.apache.org/jira/browse/THRIFT-6257
Project: Thrift
Issue Type: Bug
Components: Perl - Library
Reporter: Jens Geyer
{{lib/perl/lib/Thrift/Transport.pm:97}}:
{code}
sub readAll
{
my $self = shift;
my $len = shift;
my $data = '';
my $got = 0;
while (($got = length($data)) < $len) {
$data .= $self->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/perl}} returns an empty string from {{read()}} today -- the shipped
transports die with a {{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 die with
{{TTransportException->new({code => TTransportException::END_OF_FILE})}} rather
than repeating a call that cannot advance.
The same loop exists in {{lib/php/lib/Transport/TTransport.php}} 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)