Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

When extracting an archive, existing symbolic links in the destination directory are not overwritten even when the archive contains a symlink with a different target.

// First extraction: creates symlink "link.txt -> target1.txt"
unarchiver.extract("archive1.tar");

// Second extraction: symlink still points to target1.txt (incorrect)
// Should now point to target2.txt
unarchiver.extract("archive2.tar");

Changes

  • Replace FileUtils.resolveFile() with new File() in AbstractUnArchiver.extractFile() - the former follows symlinks, causing extraction to target the wrong file
  • Check for symlinks before existence in shouldExtractEntry() - return true immediately for symlinks to enable overwriting
  • Delete existing symlinks before creating new ones in symlink extraction path
  • Update canonical path resolution to avoid following the final symlink component during security checks

Testing

Added testSymlinkOverwriteZip() and testSymlinkOverwriteTar() to verify symlinks are properly overwritten across archive formats.

Original prompt

This section details on the original issue you should resolve

<issue_title>Symbolic links are not overwritten when extracting archive</issue_title>
<issue_description>When extracting archive if a symbolic link already exist in the target directory it is not overwritten. It continues to point to the old file. This may cause issues if the symbolic link inside the archive points to a new file.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 27, 2025 01:58
- Changed AbstractUnArchiver to use `new File(dir, entryName)` instead of
  `FileUtils.resolveFile()` which was following symlinks
- Updated shouldExtractEntry to always extract symlinks to allow overwriting
- Updated canonicalDestPath calculation to not follow symlinks
- Added deletion of existing symlink before creating new one
- Added tests to verify symlinks are properly overwritten

Co-authored-by: slachiewicz <[email protected]>
Copilot AI changed the title [WIP] Fix extraction behavior of symbolic links in archives Fix symbolic links not being overwritten during archive extraction Oct 27, 2025
Copilot AI requested a review from slachiewicz October 27, 2025 02:04
Copilot finished work on behalf of slachiewicz October 27, 2025 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Symbolic links are not overwritten when extracting archive

2 participants