Coder Social home page Coder Social logo

activestate / archiver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mholt/archiver

0.0 0.0 3.0 236 KB

Easily create and extract .zip, .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.lz4, .tar.sz, and .rar (extract-only) files with Go

Home Page: https://godoc.org/github.com/mholt/archiver

License: MIT License

Go 99.65% Shell 0.35%

archiver's People

Contributors

aviadatsnyk avatar camillescholtz avatar dmitshur avatar dsnet avatar dvrkps avatar frebib avatar gyuho avatar halfcrazy avatar jabgibson avatar jandubois avatar jchionh avatar johnarok avatar jservice-rvbd avatar justone avatar jyggen avatar mdwhatcott avatar mholt avatar petemoore avatar railsmechanic avatar shenjh369 avatar songmu avatar szymongib avatar tatsushid avatar thomasdotcodes avatar tw4452852 avatar tystuyfzand avatar valpackett avatar weingart avatar whatalnk avatar zippoxer avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

archiver's Issues

Extracting hardlinked files from Tar files is broken

What version of the package or command are you using?

v3.1.1

What are you trying to do?

Trying to Extract and/or Unarchive files which are hardlinked to other files in a tarball.

What steps did you take?

  1. tar.Unarchive(archivePath, destDir string)
  2. tar.Extract(archivePath, target, destDir string)

What did you expect to happen, and what actually happened instead?

I expected a file which is a hardlink to another file in a tarball to be unarchived successfully. However, the untarFile makes some bad assumptions about the value of hdr.Linkname and calls to the Unarchive and Extract always fail. Following is a basic example of the original behavior.

Given a tarball with the following tree:

tarball.tar
dir-1/
-- dir-2/
---- file-a
---- file-b (hardlinked to file-a)

Now we unarchive:

toDir, _ := ioutil.TempDir("", "archiver")
err := archiver.DefaultTar.Unarchive("tarball.tar", toDir)
if err != nil {
    panic(err)
}

And get an error similar to the following:

panic: reading file in tar archive: /tmp/archiver798762007/dir-1/dir-2/file-b: making hard link for: link /tmp/archiver798762007/dir-1/dir-2/file-b/dir-1/dir-2/file-a /tmp/archiver798762007/dir-1/dir-2/file-b: no such file or directory

What this error is saying is that an attempt was made to create a hardlink from new file /tmp/archiver548873541/dir-1/dir-2/file-b to existing file /tmp/archiver548873541/dir-1/dir-2/file-b/dir-1/dir-2/file-a. Observe that /tmp/archiver548873541/dir-1/dir-2/file-b/dir-1/dir-2/file-a definitely does not exist as a file, though /tmp/archiver548873541/dir-1/dir-2/file-a does.

The first part of the bug is that untarFile is joining the values of to (which is "/tmp/archiver548873541/dir-1/dir-2/file-b") and hdr.Linkname (which is "dir-1/dir-2/file-a") together to form a new, incorrect path. To get the correct path to file-a the destination path provided to Unarchive should be joined with hdr.Linkname, at least for tar (GNU tar) 1.30; this might be different with other impl's of tar.


While this "should" fix issues with calls to Unarchive, calls to Extract a directory will not immediately work. For example, given the same tarball.tar, if instead we have the following code:

toDir, _ := ioutil.TempDir("", "archiver")
err := archiver.DefaultTar.Extract("tarball.tar", "dir-1/dir-2", toDir)
if err != nil {
    panic(err)
}

The resulting panic is pretty familiar:

panic: walking file-b: extracting file dir-1/dir-2/file-b: /tmp/archiver851272160/dir-2/file-b: making hard link for: link /tmp/archiver851272160/dir-2/file-b/dir-1/dir-2/file-a /tmp/archiver851272160/dir-2/file-b: no such file or directory

Notice that the path to the new file /tmp/archiver851272160/dir-2/file-b is correct. Also notice, however, that the path to the source of the link (file-a) is that same as with the Unarchive call. So, the fix here is to create the correct path to file-a by joining the paths:

  • destination provided to Extract
  • the value from this call path.Base(target) given that target was provided to Extract
  • path.Base(hdr.Linkname) in untarFile

How do you think this should be fixed?

  1. Write unit tests around this behavior, first. Having this already would have prevented any issues to begin with.
  2. Create multiple tarballs with different tar variants (BSD, GNU, etc.) and into these tarballs put files that are hardlinked to other files in the tarball. Place these files at different dir depths within the tarball. Add these tarballs to the tests.
  3. See notes in previous section about the nature of the exact problem and how to fix.

A final note: these changes should fix unarchiving hardlinks from tar files, but no tests currently exist for creating tar files with hardlinks. It's very possible that functionality is also broken.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.