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

Stefan Bodewig commented on COMPRESS-529:
-----------------------------------------

At least the two of us share the same misunderstanding, then :)

If anything is wrong with a stream we read, we should always try to turn this 
into an {{IOException}}. This is something we don't always do, obviously, as 
[~zuevmaxim] 's issues show. When writing things are a bit different as we can 
expect the user to only hand us valid inputs IMHO.

The second issue here must expect errors as this is what 
{{TarArchiveOutputStream}} does for file names that are too long or numbers 
that are too big unless you tell it otherwise - and this is documented.

I agree we should turn the exceptions into {{IllegalArgumentException}}s - and 
document them at the public APIs that may throw them. Any client code that 
catches {{RuntimeException}}s now will automatically catch 
{{IllegalArgumentException}} as well, so we are on the safe side.

> 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, japicmp.html, 
> japicmp.html
>
>
> 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