You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Stefan Bodewig (Jira)" <ji...@apache.org> on 2020/06/07 10:51:00 UTC

[jira] [Commented] (COMPRESS-537) SevenZipOutputFile with DEFLATE compression is incorrectly decompressed

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

Stefan Bodewig commented on COMPRESS-537:
-----------------------------------------

You are ignoring the return value of {{read}}. Juts like the {{read}} method of {{InputStream}} there is no guarantee the read call will fill the array, it may read less bytes and another call (or more of them) may be necessary until {{read}} returns -1.

In your tests you seem to be lucky for some of the compression methods but you must ensure you really read the contents completely by looping over the {{read}} method.

> SevenZipOutputFile with DEFLATE compression is incorrectly decompressed
> -----------------------------------------------------------------------
>
>                 Key: COMPRESS-537
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-537
>             Project: Commons Compress
>          Issue Type: Bug
>    Affects Versions: 1.20
>            Reporter: Frotty
>            Priority: Major
>         Attachments: roxpack.atlas
>
>
> I create a 7zip archive and then load files from it. Using LZMA or BZIP2 works, but when I change it to DEFLATE the files aren't loaded correctly, parts of them are missing.
> Example kotlin code:
>  
> {code:java}
> public fun test() {
>    // SAVE
>    val target = File("target.7z")
>    val sevenZOutput = SevenZOutputFile(target)
>    sevenZOutput.setContentCompression(SevenZMethod.DEFLATE)
>    val file = File("roxpack.atlas")
>    val entry = sevenZOutput.createArchiveEntry(file, "roxpack.atlas")
>    sevenZOutput.putArchiveEntry(entry)
>    sevenZOutput.write(Files.readAllBytes(file.toPath()))
>    sevenZOutput.closeArchiveEntry()
>    sevenZOutput.close()
>    // LOAD
>    val s7f = SevenZFile(target)
>    s7f.use {
>       var nextEntry = it.nextEntry
>       do {
>          if (nextEntry.name == entry.name) {
>             val content = ByteArray(nextEntry.size.toInt())
>             s7f.read(content)
>             // with DEFLATE content array contains only 0's at the end, content string is cut off
>             println(String(content))
>             return
>          }
>          nextEntry = it.nextEntry
>       } while (nextEntry != null)
>    }
> }
> {code}
> When I extract the file using 7zip GUI tool, the file is intact, so the problem lies within the decompression. And again, this all works fine with LZMA and BZIP2.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)