Re: Using ZLib
- From: "QS Computing" <qscomputing@xxxxxxxxx>
- Date: 29 May 2005 09:55:42 -0700
QS Computing wrote:
> If only it were so easy - I tried using a repeat..until loop, checking
> the number of bytes returned in the condition at the bottom, but it
> seems that the ZLib stream's read functuin goes into an infinite loop
> somewhere.
I've found the bug: if I request more bytes than are left in the
stream, then it goes into an infinite loop in this function:
function TDecompressionStream.Read(var Buffer; Count: Longint):
Longint;
begin
FZRec.next_out := @Buffer;
FZRec.avail_out := Count;
if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
while (FZRec.avail_out > 0) do
begin
if FZRec.avail_in = 0 then
begin
FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer));
FZRec.next_in := FBuffer;
FStrmPos := FStrm.Position;
Progress(Self);
end;
CCheck(inflate(FZRec, 0));
end;
Result := Count;
end;
The inflate() method is in the pre-compiled C, so I can't test it, but
when Count>bytes left, inflate() sets FZRec.avail_out to 0, otherwise
it doesn't do anything.
Perhaps I could use one of the following functions, both declared in
the ZLib unit, to test to see if the bug is in the Delphi code or if
it's in the C:
{ DecompressBuf decompresses data, buffer to buffer, in one call.
In: InBuf = ptr to compressed data
InBytes = number of bytes in InBuf
OutEstimate = zero, or est. size of the decompressed data
Out: OutBuf = ptr to newly allocated buffer containing decompressed
data
OutBytes = number of bytes in OutBuf }
procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
{ DecompressToUserBuf decompresses data, buffer to buffer, in one call.
In: InBuf = ptr to compressed data
InBytes = number of bytes in InBuf
Out: OutBuf = ptr to user-allocated buffer to contain decompressed
data
BufSize = number of bytes in OutBuf }
procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
const OutBuf: Pointer; BufSize: Integer);
TIA,
- QS Computing
.
- Follow-Ups:
- Re: Using ZLib
- From: J French
- Re: Using ZLib
- From: QS Computing
- Re: Using ZLib
- References:
- Using ZLib
- From: QS Computing
- Re: Using ZLib
- From: J French
- Re: Using ZLib
- From: QS Computing
- Re: Using ZLib
- From: J French
- Re: Using ZLib
- From: QS Computing
- Using ZLib
- Prev by Date: Trouble downloading pages
- Next by Date: Re: checking arbitrary bounds
- Previous by thread: Re: Using ZLib
- Next by thread: Re: Using ZLib
- Index(es):
Relevant Pages
|
|