commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "yiang li (Jira)" <j...@apache.org>
Subject [jira] [Updated] (COMPRESS-496) SevenZFile.read got an exception when extracting empty file
Date Fri, 18 Oct 2019 08:43:00 GMT

     [ https://issues.apache.org/jira/browse/COMPRESS-496?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

yiang li updated COMPRESS-496:
------------------------------
    Description: 
When extracting an empty file in SevenZFile, an exception will be thrown. This is because
the `deferredBlockStreams` in SevenZFile was clear here

 
{code:java}
if (folderIndex < 0) {
 deferredBlockStreams.clear();
 // TODO: previously it'd return an empty stream?
 // new BoundedInputStream(new ByteArrayInputStream(new byte[0]), 0);
 return;
}{code}
Maybe an empty stream should be added to deferredBlockStreams here as the TODO said?

 

Code to reproduce the exception
{code:java}
byte[] buffer = new byte[4096];
 String destination = "/output/dir/of/7z";
 SevenZFile sevenZFile = new SevenZFile(new File("/file/to/extract.7z"));
 SevenZArchiveEntry entry;
 while ((entry = sevenZFile.getNextEntry()) != null){
 if (entry.isDirectory())
{ continue; }
File curfile = new File(destination, entry.getName());
 File parent = curfile.getParentFile();
 if (!parent.exists())
{ parent.mkdirs(); }
FileOutputStream out = new FileOutputStream(curfile);
while(sevenZFile.read(buffer, 0, buffer.length) > 0)
{ out.write(buffer); out.close(); }
}
{code}

  was:
When extracting an empty file in SevenZFile, an exception will be thrown. This is because
the `deferredBlockStreams` in SevenZFile was clear here

 
{code:java}
if (folderIndex < 0) {
 deferredBlockStreams.clear();
 // TODO: previously it'd return an empty stream?
 // new BoundedInputStream(new ByteArrayInputStream(new byte[0]), 0);
 return;
}{code}
Maybe an empty stream should be added to deferredBlockStreams here as the TODO said?

 

Code to reproduce the exception

 
{code:java}
byte[] buffer = new byte[4096];
 String destination = "/output/dir/of/7z";
 SevenZFile sevenZFile = new SevenZFile(new File("/file/to/extract.7z"));
 SevenZArchiveEntry entry;
 while ((entry = sevenZFile.getNextEntry()) != null){
 if (entry.isDirectory())
{ continue; }
File curfile = new File(destination, entry.getName());
 File parent = curfile.getParentFile();
 if (!parent.exists())
{ parent.mkdirs(); }
FileOutputStream out = new FileOutputStream(curfile);
while(sevenZFile.read(buffer, 0, buffer.length) > 0)
{ out.write(buffer); out.close(); }
}
{code}


> SevenZFile.read got an exception when extracting empty file
> -----------------------------------------------------------
>
>                 Key: COMPRESS-496
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-496
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: yiang li
>            Priority: Minor
>
> When extracting an empty file in SevenZFile, an exception will be thrown. This is because
the `deferredBlockStreams` in SevenZFile was clear here
>  
> {code:java}
> if (folderIndex < 0) {
>  deferredBlockStreams.clear();
>  // TODO: previously it'd return an empty stream?
>  // new BoundedInputStream(new ByteArrayInputStream(new byte[0]), 0);
>  return;
> }{code}
> Maybe an empty stream should be added to deferredBlockStreams here as the TODO said?
>  
> Code to reproduce the exception
> {code:java}
> byte[] buffer = new byte[4096];
>  String destination = "/output/dir/of/7z";
>  SevenZFile sevenZFile = new SevenZFile(new File("/file/to/extract.7z"));
>  SevenZArchiveEntry entry;
>  while ((entry = sevenZFile.getNextEntry()) != null){
>  if (entry.isDirectory())
> { continue; }
> File curfile = new File(destination, entry.getName());
>  File parent = curfile.getParentFile();
>  if (!parent.exists())
> { parent.mkdirs(); }
> FileOutputStream out = new FileOutputStream(curfile);
> while(sevenZFile.read(buffer, 0, buffer.length) > 0)
> { out.write(buffer); out.close(); }
> }
> {code}



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

Mime
View raw message