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

Peter Lee commented on COMPRESS-529:
------------------------------------

Disclaimer : I'm not that familiar with kotlin so feel free to tell if I make 
any mistakes. :)

For the second issue(a.k.a the LongName.tar issue) : 

If I understand this issue correctly, you're creating a tar entry with a name 
which is longer than 100 byte. Then you got an Runtime Exception which is 
telling you that the file name is too long. Isn't it?

Actually this is expected exception cause you didn't set the longFileMode for 
aos and it's set as default value : LONGFILE_ERROR, which means we will throw 
an exception if the file name is too long.

Just try something like 
{code:java}
aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
{code}
and you would not get this exception any more.

 

Or maybe you are just talking that we should throw IOException instead of 
RuntimeException?

> Tar decompression fails with runtime exceptions
> -----------------------------------------------
>
>                 Key: COMPRESS-529
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-529
>             Project: Commons Compress
>          Issue Type: Bug
>    Affects Versions: 1.20
>            Reporter: Maksim Zuev
>            Priority: Major
>         Attachments: LongName.tar, NumberFormatException.tar
>
>
> This Kotlin code fails with exception(NumberFormatException.tar is in the 
> attachment)
> Exception in thread "main" java.lang.NumberFormatException: For input string: 
> "143266�921.098285006"
>  at 
> java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
>  at 
> java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
>  at java.base/java.lang.Double.parseDouble(Double.java:543)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveEntry.processPaxHeader(TarArchiveEntry.java:1161)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveEntry.updateEntryFromPaxHeaders(TarArchiveEntry.java:1093)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveInputStream.applyPaxHeadersToCurrentEntry(TarArchiveInputStream.java:757)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveInputStream.paxHeaders(TarArchiveInputStream.java:562)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:404)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextEntry(TarArchiveInputStream.java:799)
>  at ru.example.kotlinfuzzer.tests.MainKt.main(main.kt:69)
>  at ru.example.kotlinfuzzer.tests.MainKt.main(main.kt)
> {code:java}
> import org.apache.commons.compress.archivers.ArchiveStreamFactory
> import java.io.File
> fun main() {
>     val tar = File("NumberFormatException.tar")
>     ArchiveStreamFactory().createArchiveInputStream("tar", 
> tar.inputStream()).use { ais ->
>         ais.nextEntry
>         ais.readAllBytes()
>     }
> }
> {code}
> This Kotlin code fails with exception(LongName.tar is in the attachment)
> Exception in thread "main" java.lang.RuntimeException: file name 'asidhuasih a
>  sdjn osdn 
>  sdvs ndv
>  asdjbhasdb asb iasbfi basdigf basduio 
>  asdkhasjdhasd
>  asdjkhasnjddjasjdas
>  /?' is too long ( > 100 bytes)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.handleLongName(TarArchiveOutputStream.java:683)
>  at 
> org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.putArchiveEntry(TarArchiveOutputStream.java:358)
>  at ru.example.kotlinfuzzer.tests.MainKt.test(main.kt:20)
>  at ru.example.kotlinfuzzer.tests.MainKt.main(main.kt:8)
>  at ru.example.kotlinfuzzer.tests.MainKt.main(main.kt)
> {code:java}
> import org.apache.commons.compress.archivers.ArchiveStreamFactory
> import org.apache.commons.compress.archivers.tar.TarArchiveEntry
> import java.io.File
> fun main() {
>     test(File("LongName.tar"))
> }
> fun test(tar: File) {
>     val (decompressed, name) = 
> ArchiveStreamFactory().createArchiveInputStream("tar", tar.inputStream()).use 
> { ais ->
>         val entry = ais.nextEntry
>         ais.readAllBytes() to entry.name
>     }
>     File.createTempFile("apache_", ".tar").also {
>         ArchiveStreamFactory().createArchiveOutputStream("tar", 
> it.outputStream()).use { aos ->
>             val entry = TarArchiveEntry(name)
>             entry.size = decompressed.size.toLong()
>             aos.putArchiveEntry(entry)
>             try {
>                 aos.write(decompressed)
>             } finally {
>                 aos.closeArchiveEntry()
>             }
>         }
>     }
> }
> {code}
>  
> IOException expected



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

Reply via email to