You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Darryl L. Pierce (JIRA)" <ji...@apache.org> on 2017/07/18 13:45:00 UTC

[jira] [Commented] (COMPRESS-418) ZipArchiveEntry duplicates the size field from ZipEntry

    [ https://issues.apache.org/jira/browse/COMPRESS-418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16091558#comment-16091558 ] 

Darryl L. Pierce commented on COMPRESS-418:
-------------------------------------------

Code for creating the archive:

{code:java}
        ZipArchiveOutputStream zoutput = null;
        try
        {
            zoutput = (ZipArchiveOutputStream )new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP,
                                                                                                    new FileOutputStream(filename));

            // TODO write the comic meta-data to the archive
            for (int index = 0;
                 index < source.getPageCount();
                 index++)
            {
                // TODO if the page is deleted, then skip it
                Page page = source.getPage(index);
                ZipArchiveEntry entry = new ZipArchiveEntry(page.getFilename());
                entry.setMethod(ZipArchiveEntry.DEFLATED);
                logger.debug("Adding entry: " + page.getFilename() + " size=" + page.getContent().length);
                entry.setSize(page.getContent().length);
                zoutput.putArchiveEntry(entry);
                zoutput.write(page.getContent());
                zoutput.closeArchiveEntry();
            }

            // zoutput.close();
        }
        catch (IOException
               | ArchiveException error)
        {
            throw new ArchiveLoaderException("error creating comic archive", error);
        }
{code}

Code for reading the archive:


{code:java}
        File file = validateFile(comic);

        try
        {
            FileInputStream istream = new FileInputStream(file);
            ZipArchiveInputStream input = (ZipArchiveInputStream )new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
                                                                                                                      istream);
            ZipArchiveEntry entry = null;
            byte[] result = null;

            while ((entry = input.getNextZipEntry()) != null)
            {
                String filename = entry.getName();
                if (entryName == null || entryName.equals(filename))
                {
                    byte[] content = this.loadContent(entry.getName(), entry.getSize(), input);
                    // if we were looking for a file, then we're done
                    if (entryName != null)
                    {
                        logger.debug("Return content for entry");
                        result = content;
                        break;
                    }
                    else
                    {
                        logger.debug("Processing entry content");
                        processContent(comic, filename, content);
                    }
                }
            }

            input.close();
            istream.close();

            return result;
        }
        catch (IOException
               | ArchiveException error)
        {
            throw new ArchiveLoaderException("unable to open file: " + file.getAbsolutePath(), error);
        }
{code}



> ZipArchiveEntry duplicates the size field from ZipEntry
> -------------------------------------------------------
>
>                 Key: COMPRESS-418
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-418
>             Project: Commons Compress
>          Issue Type: Bug
>          Components: Archivers
>    Affects Versions: 1.14
>         Environment: Java 1.8.0_131
> Apache Compress 1.14
>            Reporter: Darryl L. Pierce
>            Priority: Critical
>
> I create an archive using Apache Compress. I can read the archive fine using 7zip and JAR (from the JDK).
> When I read the same archive using Apache Compress libraries, I get a NegativeArraySizeException on every entry.
> When I read any other archive using Apache Compress libraries, I do not get the NegativeArraySizeException on entries.
> When I debug this, I see that the ZipArchiveEntry object has two instance variables named size (one it defines, which contains the correct size, and one it inherits from ZipEntry which is -1). And it seems that, on Apache Compress-created archives, it's always returning the inherited value and not the one defined by ZipArchiveEntry.
> In my code, I am only use instances of ZipArchiveEntry.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)