jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

    I have a simple test case producing a sure ArrayOutOfBoundException in jzlib 1.0.7 depending on the data subsequently written to one and the same instance of ZOutputStream.

    Stacktrace:

    java.lang.ArrayIndexOutOfBoundsException: 587
    at com.jcraft.jzlib.Tree.d_code(Tree.java:149)
    at com.jcraft.jzlib.Deflate.compress_block(Deflate.java:691)
    at com.jcraft.jzlib.Deflate._tr_flush_block(Deflate.java:897)
    at com.jcraft.jzlib.Deflate.flush_block_only(Deflate.java:772)
    at com.jcraft.jzlib.Deflate.deflate_slow(Deflate.java:1195)
    at com.jcraft.jzlib.Deflate.deflate(Deflate.java:1567)
    at com.jcraft.jzlib.ZStream.deflate(ZStream.java:133)
    at com.jcraft.jzlib.ZOutputStream.write(ZOutputStream.java:102)
    at com.jcraft.jzlib.JZLibTestCase.main(JZLibTestCase.java:51)
    at JZLibTestCase.main(JZLibTestCase.java:28)

    The problem occurs very rarely and depends on the data subsequentially written to an open ZOutputStream from jzlib.

    Do you have a hint how to fix this? Have you ever heard of this?
    Attached Files Attached Files

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

    Can you post the code in-line (using code tags). Many people here won't open attachments.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Apr 2011
    Posts
    3

    Re: jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

    Of course, but the attachment is necessary to reproduce it, absolutely. You most probable won't be able to reproduce it with own data to be compressed. We got this problem after years running jzlib successfully in productive environments. The test data is imported from files, not in the code itself.

    Here is the code for importing:

    Code:
    import java.io.*;
    import java.util.*;
    
    import com.jcraft.jzlib.*;
    
    public class JZLibTestCase {
    
      public static void main(String[] args)
      {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStream zout;
        try
        {
          List<File> files = getFileListing(new File("dump"));
    
          // Even Z_DEFAULT_COMPRESSION does not help
          zout = new ZOutputStream(bos, JZlib.Z_BEST_COMPRESSION);
          // Commenting this in, there is no error any longer
          //zout = new ZOutputStream(bos, JZlib.Z_NO_COMPRESSION);
    
          // Writing only contents of the last file on the list does not help
          // The bug depends on the internal state of this ZOutputStream instance.
          //File file = new File("/home/rkrell/test/jzlib/com.jcraft.jzlib.ZOutputStream@38a97b0b_1302538064113_0_8192");
    
          for(File file : files ){
            System.out.println("File: " + file.getName());
            byte[] b = getBytesFromFile(file);
            zout.write(b, 0, b.length);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    
      static private List<File> getFileListing(File dir)
      throws FileNotFoundException
      {
        List<File> result = getFileListingNoSort(dir);
        Collections.sort(result);
        return result;
      }
    
      static private List<File> getFileListingNoSort(File dir)
      throws FileNotFoundException
      {
        List<File> result = new ArrayList<File>();
        File[] filesAndDirs = dir.listFiles();
        List<File> filesDirs = Arrays.asList(filesAndDirs);
        for(File file : filesDirs) {
          if ( file.isFile() ) {
            result.add(file);
          }
        }
        return result;
      }
    
      static private byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);
        long length = file.length();
        byte[] bytes = new byte[(int)length];
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }
        is.close();
        return bytes;
      }
    
    }

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

    If it seems to be a problem in the jzLib library code, report it to JCraft.

    Successful software always gets changed...
    F. Brooks
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Apr 2011
    Posts
    3

    Re: jzlib 1.0.7: ArrayOutOfBoundException in ZOutputStream.write()

    I know this, and it is already reported to JCraft. But it is open source, I ask here, whether this has one already solved. I haven't got any echo from JCraft to this time.
    Switching this test case to java.util.zip and GZOutputStream works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center