#1 2013-09-24 07:21:45

Gigo
Member
From: Split, Croatia
Registered: 2012-01-27
Posts: 14

SynZip: TZipWrite create from existing empty ZIP

Hi Arnaud,

I encountered an issue with TZipWrite.CreateFom constructor when I try to add files to empty archive.

This code will fail :

procedure Fail;
var
  ZW : TZipWrite;
begin
  if FileExists('Test.zip') then
    DeleteFile('Test.zip');
  // this will pass
  ZW := TZipWrite.Create('Test.zip');
  if Assigned(ZW) then
    FreeAndNil(ZW);

  // this will raise an exception
  ZW := TZipWrite.Create('Test.zip');
  if Assigned(ZW) then
    FreeAndNil(ZW);
end;

Actually the problem is in TZipRead.Create when searching for ExeOffset variable.
if I change code to :

  // existing code
  ExeOffset := -1;
  for i := ZipStartOffset to Size-5 do
    if PCardinal(@buf[i])^+1=$04034b51 then begin // +1 to avoid finding it in the exe part
      ExeOffset := i;
      break;
    end;
  // added
  if ExeOffset<0 then begin
  for i := ZipStartOffset to Size-5 do
    if PCardinal(@buf[i])^+1=$06054b51 then begin // +1 to avoid finding it in the exe part
      ExeOffset := i;
      break;
    end;
  end;
  // existing code
  if ExeOffset<0 then begin
    Unmap;
    raise Exception.Create('No ZIP found');
    exit;
  end;

then everything works (empty ZIP file does not start with file entry).


Keep up the great work,

Cheers

Offline

#2 2013-09-24 11:37:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,552
Website

Re: SynZip: TZipWrite create from existing empty ZIP

We have fixed this unexpected error when adding files e.g. via TZipWrite.CreateForm() to an empty archive.
http://synopse.info/fossil/info/bf4577eccf

Thanks a lot for the feedback and patch proposal!
smile

Offline

Board footer

Powered by FluxBB