mxmlnkn / ratarmount

Access large archives as a filesystem efficiently, e.g., TAR, RAR, ZIP, GZ, BZ2, XZ, ZSTD archives
MIT License
699 stars 36 forks source link

Mounting a password-protected 7z archive #141

Open TadavomnisT opened 3 weeks ago

TadavomnisT commented 3 weeks ago

Is it possible to use ratarmount to mount to a password-protected (encrypted) 7z archive?

I tried this:

ratarmount archive.7z mount-point

UPDATE: I also tried this:

ratarmount --password [PASSWORD] archive.7z mount-point

It makes a mount file, but it's not a valid file since no password was used.


PS: I'm trying to extract large 7z nested archives to get SomeFile.ext, like this:

OuterArchive.7z (200GB/Encrypted)
    └── InnerArchive.7z (200GB/Encrypted)
        ├── SomeFile.ext (1GB)
        └── ...

Please see this question for more info.

mxmlnkn commented 3 weeks ago

Sorry for the late answer. I was on vacation.

Passwords should work the same way you pointed out. But, it seems that the underlying libarchive is missing password support for 7z files :(. I even documented it in the tests, which is good, because I did forget it:

    @staticmethod
    # 7z : libarchive.exception.ArchiveError: The file content is encrypted, but currently not supported
    #      (errno=-1, retcode=-30, archive_p=94443813387248)
    # RAR: libarchive.exception.ArchiveError: Unsupported block header size (was 4, max is 2)
    #      (errno=84, retcode=-30, archive_p=94443813892640)
    # Basically only ZIP has encryption support provided by libarchive, much less than I would have thought.
    # https://github.com/libarchive/libarchive/issues/579#issuecomment-118440525
    # @pytest.mark.parametrize("compression", ["7z", "rar", "zip"])
    @pytest.mark.parametrize('compression', ['zip'])
    def test_password(compression):

Missing feature can be reproduced with:

echo bar > foo
7z a -pPASSWORD foo.7z foo
ratarmount --password PASSWORD foo.7z mounted

Support for this should ideally be added to libarchive upstream. Alternatively, other 7z wrapper such as py7z could be used.

Error-handling on ratarmount side could be better though. For me, it showed the file lists, but when trying to access a file, I would get an Input/Output error. A helpful message only shows with ratarmount -f -d 3 ...

TadavomnisT commented 3 weeks ago

@mxmlnkn Thanks for you time.