Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Oct : TIdZLibCompressorBase.DecompressGZipStream HAVE BUG !!

www.cryer.info
Managed Newsgroup Archive

TIdZLibCompressorBase.DecompressGZipStream HAVE BUG !!

Subject:TIdZLibCompressorBase.DecompressGZipStream HAVE BUG !!
Posted by:"child" (chi..@88oo.com)
Date:Tue, 11 Oct 2005 19:27:22

watch the ************** Line !!!


procedure TIdZLibCompressorBase.DecompressGZipStream(AInStream, AOutStream :
TIdStream);

  procedure GotoDataStart;
  var LFlags:TIdBytes; //used as a byte
      LExtra:TIdBytes; //used as a word
      LNullFindChar:TIdBytes; //used as char
  begin
    SetLength(LFlags,1);
    SetLength(LExtra,2);
    SetLength(LNullFindChar,1);

    //skip id1,id2,CompressionMethod (CM should=8)
    AInStream.Seek(3,IdFromCurrent);
    //read Flag
    TIdStreamHelper.ReadBytes(AInStream,LFlags,1);
    //skip mtime,xfl,os
    AInStream.Seek(6,IdFromCurrent);

    // at pos 10 now

    if LFlags[0] and $4 = $4 then begin // FEXTRA
      AInStream.Read(LExtra,2);
      AInStream.Seek( BytesToWord( LExtra), IdFromCurrent);
    end;

    if LFlags[0] and $8 = $8 then begin // FNAME
      repeat
// original        AInStream.Read(LNullFindChar, 1);
**********************************************************
// should
        AInStream.Read(LNullFindChar[0], 1);
      until LNullFindChar[0]=0;
    end;

    if LFlags[0] and $10 = $10 then begin // FCOMMENT
      repeat
//original        AInStream.Read(LNullFindChar, 1);
**********************************************************
// should
        AInStream.Read(LNullFindChar[0], 1);
      until LNullFindChar[0]=0;
    end;

    if LFlags[0] and $2 = $2 then begin // FHCRC
      AInStream.Seek(2, IdFromCurrent); // CRC16
    end;
  end;

var
  LBytes : TIdBytes;
begin
  Assert(AInStream<>nil);

  GotoDataStart;
  AInStream.Seek(-2, IdFromCurrent);
  SetLength(LBytes, 2);
  LBytes[0] := $78; //7=32K blocks, 8=deflate
  LBytes[1] := $9C;
  TIdStreamHelper.Write(AInStream,LBytes,2);
  AInStream.Seek(-2, IdFromCurrent);
  AInStream.size := AInStream.size - 8; // remove the CRC32 and the size
  AInStream.Position := 0;
  InflateStream(AInStream, AOutStream);
end;

Replies:

www.cryer.info
Managed Newsgroup Archive