Here is a question - do you expect the complete compressed buffer to be present in the sysread you do directly before the call to inflate ?
Looking at the code I'm guessing that it isn't. Please correct me if that is wrong.
So, assuming that is the case, the code in its current state has a number of problems.
Firstly, the code doesn't explicitly handle the end of the compressed data stream at all.
In this section of code you are using the absence of any data in $nout to flag an error. That isn't safe
my ($nout, $status) = $zlib->inflate($s->{buf}); if (! defined $nout) { print "Error inflating: errnum: $status\n"; } else { # Inflation successful $s->{buf} = $nout; $nread = length ($nout); }
You should instead be checking the value of $status returned from inflate. If you get Z_OK, inflate has succeeded and the content from the next sysread (when _fillbuff gets called again) can be fed to inflate. If you get Z_STREAM_END that signals the end of the compressed data stream, so the next sysread can't be fed to inflate (unless the telnet protocol allows multiple zlib streams). Any other status code means an error of some sort in the compressed data stream.
One other issue you need to take care of when you get Z_STREAM_END is the presence of trailing data directly after the end of the zlib data stream (don't know the details of how telnet works with zlib, so I don't know if this will happen in practice). If there is trailing data the $buf variable will contain it (inflate will remove all compressed data from the buffer parameter you pass it). In this case I think you can deak with that by changing this line
$s->{buf} = $nout
to this
$s->{buf} = $nout . $buff;
Next potential problem is pushback_buf. That looks like it is used to store data that hasn't been processed by the telnet protocol. The problem is that the data from sysread is prefixed by any pushback_buf that exists. If a previous call to __fillbuf made a call to inflate and the telnet module hasn't used up all of the data read, you end up trying to uncompress something that is prefixed with uncompressed data.
In reply to Re^15: Can't decompress zlib compression stream with Compress:Zlib
by pmqs
in thread Can't decompress zlib compression stream with Compress:Zlib
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |