Re: Using ZLib
- From: erewhon@xxxxxxxxxx (J French)
- Date: Mon, 30 May 2005 11:02:03 +0000 (UTC)
On 29 May 2005 09:55:42 -0700, "QS Computing" <qscomputing@xxxxxxxxx>
wrote:
>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:
I checked my Delphi 4P CD and to my surprize found ZLib on it
If your version of ZLib is the same as mine then the problem you have
is that someone has hacked the code below, and /removed/ the exit
condition, see below :-
>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));
{ this code appears to have been removed}
if FZRec.avail_in = 0 then
begin
Result := Count - FZRec.avail_out;
Exit;
end;
> 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.
I can't quite see why anyone should have removed the lines containing
the main exit condition, and suggest that you check your Delphi CD.
Also check other routines, this might not be the only spot of
tampering.
It is odd that those lines should be removed, as without them I can't
see any way the routine can exit with Result <> Count which means that
the requestor needs to be explicitly jiggering Count outside the
routine to ensure that they are asking for /exactly/ the decompressed
size of the uncompressed remaining data.
That or always reading 1 byte at a time - which is dim
I can't believe that Borland would have made that change.
This looks very like some routines from PKWARE that I worked on a long
time ago - 'Inflate' worked in much the same way
- I suspect that these OBJ files have a similar origin
Further to GB's suggestion that you use VCL Zip aka KPZip, which I was
impressed enough to buy, the compression routine should be Huffman as
used in PKZip - and therefore exactly the same.
It is worth checking.
.
- 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
- Re: Using ZLib
- From: QS Computing
- Using ZLib
- Prev by Date: COM interfaces
- Next by Date: Re: MODI OCR "class not registered"
- Previous by thread: Re: Using ZLib
- Next by thread: Re: Using ZLib
- Index(es):
Relevant Pages
|
|