Re: Using ZLib



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.

.



Relevant Pages

  • Re: how do people feel about exit function from loop
    ... never mind that structured programming says you shouldn't use them. ... When I see a While loop, I know that there are conditions to be fulfilled, can examine them all at once, then find out what I do as long as those conditions aren't fulfilled. ... The problem with the first approach is that there are more than one exit from the routine, ...
    (microsoft.public.vb.general.discussion)
  • Re: LEAVE
    ... If by "structured" you mean a single exit for the routine, ... structure you happen to be in, inside the loop. ...
    (comp.lang.forth)
  • Re: [PATCH RFD] alternative kobject release wait mechanism
    ... exit() routines will have to ... where the driver cannot afford to wait for all the references ... exit routine, but to make things work the routine would have to wait for ... pass an owner to the embedded kobject, but I want to try it out a little ...
    (Linux-Kernel)
  • Re: Math libarary
    ... thought would have been a bette routine than Math.Exp and I was wrong;/ ... Both of these depend on S only but have to take into account the boundaries. ... Right now I have two functions that essentially loop over S seperately. ... The following is the code I use to compute the laplacian of a scalar field. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Infinite Loops and Explicit Exits
    ... I'm a bit confused on this, having never seen ICL machines. ... It looks like the BRN is a 'branch routine' opcode? ... And exit point is some address inside the routine 'start' where you ... > Because removing it from the language would break too many programs. ...
    (comp.lang.cobol)