FIX: Zip plugin - allow cancelling TAR archive packing mid-operation (#2874)

* FIX: zip plugin - allow cancelling TAR archive packing mid-operation

TAbTarArchive.SaveArchive iterated all items without ever checking
the abort flag, making it impossible to cancel a TAR/TGZ/TBZ2 pack
operation until all files had been written.

Add a DoArchiveProgress call with abort check after each item in the
save loop, identical to the pattern already used in TAbZipArchive.SaveArchive
(abziptyp.pas) and in all extract loops (abarctyp.pas).

When the user cancels, EAbUserAbort is raised, caught in PackFilesW,
and the incomplete archive is deleted if it did not exist before packing.

* FIX: zip plugin - prevent crash on TAR abort inside GZip archive

When TAbUserAbort propagates out of TAbTarArchive.SaveArchive (e.g.
from the abort check added to the save loop), it exits the IsGzippedTar
branch of TAbGzipArchive.SaveArchive without calling SwapToGzip. The
outer finally block then compares FStream (which equals FTarStream,
possibly nil) with NewStream (FGzStream) and incorrectly frees
NewStream. The destructor later calls SwapToGzip (restoring FStream to
the already-freed FGzStream) and then frees FStream a second time,
causing an access violation.

Fix: compare FGzStream instead of FStream in the finally condition.
FGzStream always holds the original gzip stream reference and is never
changed by SwapToTar/SwapToGzip, so the NewStream ownership check is
correct regardless of which swap state the archive is in.

---------

Co-authored-by: heredie <heredie@localhost>
(cherry picked from commit 6123a21ed0)
This commit is contained in:
EH 2026-05-23 03:12:23 -06:00 committed by Alexander Koblov
commit 197028a1ed
2 changed files with 8 additions and 1 deletions

View file

@ -1302,7 +1302,10 @@ begin
DoArchiveProgress( 100, Abort );
finally {NewStream}
OutGzHelp.Free;
if (FStream <> NewStream) then
{ Use FGzStream (not FStream) so the comparison is correct even when
SwapToTar was called and an exception prevented SwapToGzip from running.
FGzStream always holds the original gzip stream reference. }
if (FGzStream <> NewStream) then
NewStream.Free;
end;
end;

View file

@ -2556,6 +2556,10 @@ begin
end;
end; { aaAdd ... }
end; { case }
DoArchiveProgress(AbPercentage(succ(i), Count), Abort);
if Abort then
raise EAbUserAbort.Create;
end; { for i ... }
if NewStream.Position > 0 then