You are not logged in.
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
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!
Offline