1. Harmony
  2. HARMONY-6637

[classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source


    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.0M16
    • Component/s: Classlib
    • Labels:
    • Estimated Complexity:


      There's code in the inflate() method of classlib/modules/archive/src/main/java/java/util/zip/Inflater.java (r926871 and earlier) which short-cuts the inflation if the parameter 'nbytes' is 0 - ie if the caller is actually requesting zero bytes:

      if (nbytes == 0)

      { return 0; --- Don't do any work: DON'T UPDATE THE *FINISHED* FLAG! }

      While it seems reasonable, it is in fact incompatible with the RI (which does attempt to process the deflated source data in the nbytes, and will update the finished() flag) - and so causes problems with a common inflation loop scenario, where the code loops to populate a destination byte-array of known size while inflater.finished() is not true. Even if the destination byte-array is known to be zero-length (e.g. we're deflating a zero-length file), the coder might still reasonably expect calling inflate() to set the finished() flag to true. However, unlike the RI, Harmony implementation does not update the finished() flag, which leads to an infinite loop or some other bad outcome.

      Bit short on time right now, will try to provide a better testcase and possibly a patch at a later date.

      best regards,
      Roberto Tyley

      1. Main.java
        1 kB
        Roberto Tyley


        Roberto Tyley created issue -
        Roberto Tyley made changes -
        Field Original Value New Value
        Attachment Main.java [ 12455664 ]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Tim Ellison made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 5.0M16 [ 12315337 ]
        Resolution Fixed [ 1 ]
        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]


          • Assignee:
            Tim Ellison
            Roberto Tyley
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: