libarchive / libarchive

Multi-format archive and compression library
http://www.libarchive.org
Other
3.03k stars 768 forks source link

Cannot read 7zip, etc, with archive_read_open_FILE #437

Open kwrobot opened 9 years ago

kwrobot commented 9 years ago

Original issue 328 created by Google Code user moonstar0825 on 2013-07-23T05:21:12.000Z:

<b>What steps will reproduce the problem?</b>

1. unzip more.zip (more.com, more.7z, more_7zsfx.exe, more_zipsfx.exe )
2. gcc 1.c -larchive
3. ./a.out more.7z

<b>What is the expected output? What do you see instead?</b>

    more.7z and more_7zsfx.exe
        use archive_read_open_filename, the extract file is correct
        use archive_read_open_FILE, the extract file size is 0

    more_zipsfx.exe
        use archive_read_open_filename, the extract file is correct
        use archive_read_open_FILE, output &quot;not supported&quot;

<b>What version are you using?</b>

    libarchive-3.1.2

<b>On what operating system?</b>

    ubuntu 13.04 x64

<b>How did you build?  (cmake, configure, or pre-packaged binary)</b>

    cmake

<b>What compiler or development environment (please include version)?</b>

    gcc version 4.7.3

<b>Please provide any additional information below.</b>

    #include &lt;stdio.h&gt;
    #include &lt;stdlib.h&gt;

    #include &lt;archive.h&gt;
    #include &lt;archive_entry.h&gt;

    int main(int argc, char* argv[])
    {
        struct archive *a;
        a = archive_read_new();

        archive_read_support_filter_all(a);
        archive_read_support_format_all(a);

        int r;
        //r = archive_read_open_filename(a, argv[1], 10240);

        FILE *in = fopen(argv[1], &quot;rb&quot;);
        r = archive_read_open_FILE(a, in);

        if (r != ARCHIVE_OK)
        {
            printf(&quot;not supported\n&quot;);
            return 1;
        }

        int size;
        char buf[1024];

        FILE *out = fopen(&quot;tmpfile&quot;, &quot;wb+&quot;);

        struct archive_entry *entry;

        while(archive_read_next_header(a, &amp;entry) == ARCHIVE_OK) 
        {
            while((size = archive_read_data(a, buf, 1024)) &gt; 0)
                fwrite(buf, sizeof(char), size, out);

            if(archive_errno(a) != ARCHIVE_OK)
                printf(&quot;%s\n&quot;, archive_error_string(a));

            archive_read_data_skip(a);
        }

        fclose(out);
        fclose(in);

        archive_read_free(a);
        return 0;
    }

See attachment: more.zip

kwrobot commented 9 years ago

Comment #1 originally posted by kientzle on 2013-07-23T05:38:37.000Z:

Currently, archive_read_open_FILE does not support seeking.  archive_read_open_filename does.

Self-extracting Zip archives, 7z, and some other formats cannot be read without seeking.

Patches to add seek support for archive_read_open_FILE would be appreciated.
kwrobot commented 9 years ago

Comment #2 originally posted by kientzle on 2013-11-24T17:16:50.000Z:

Updating bug title to more accurately reflect the actual issue.