You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Roberto Tyley (JIRA)" <ji...@apache.org> on 2010/08/30 17:30:53 UTC

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

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

                 Key: HARMONY-6637
                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Roberto Tyley
            Priority: Critical


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






-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915291#action_12915291 ] 

Tim Ellison commented on HARMONY-6637:
--------------------------------------

Roberto, if you have a simple program demonstrating the problem that would be very helpful.

Thanks.


> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Priority: Critical
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Roberto Tyley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915321#action_12915321 ] 

Roberto Tyley commented on HARMONY-6637:
----------------------------------------

The infinite loop that occurs in Harmony is because inflater.finished() is never true - in the RI, the flag would get set to true even if you were asking for the flation of zero bytes, but in Harmony, if numBytes is zero, the flag will never get set.

byte[] buffer=new byte[numBytes]; // the developer knows how big the data is going to be, that info is available to him through some other metadata
int numRead=0;
while (!inflater.finished()) { // reasonable assumption by the developer here!
    int inflatedChunkSize=inflater.inflate(buffer, numRead, buffer.length-numRead); // 'buffer.length-numRead' is zero, harmony will not set the flag
    numRead+=inflatedChunkSize;;
}

... consequently, an infinite loop :-/



> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Priority: Critical
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison closed HARMONY-6637.
--------------------------------


Verified by Roberto.


> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M16
>
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916978#action_12916978 ] 

Hudson commented on HARMONY-6637:
---------------------------------

Integrated in Harmony-select-1.5-head-linux-x86_64 #127 (See [https://hudson.apache.org/hudson/job/Harmony-select-1.5-head-linux-x86_64/127/])
    Apply fix for HARMONY-6637 ([classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source)


> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M16
>
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916887#action_12916887 ] 

Hudson commented on HARMONY-6637:
---------------------------------

Integrated in Harmony-1.5-head-linux-x86_64 #974 (See [https://hudson.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/974/])
    Apply fix for HARMONY-6637 ([classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source)


> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M16
>
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Roberto Tyley (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roberto Tyley updated HARMONY-6637:
-----------------------------------

    Attachment: Main.java

This file demonstrates the difference between Harmony and the RI for java.util.zip.Inflater

The RI output is:

Inflating 10 bytes in a loop... [ 10 ] ...read total 10 bytes
Inflating 5 bytes in a loop... [ 5 ] ...read total 5 bytes
Inflating 0 bytes in a loop... [ 0 ] ...read total 0 bytes

The Harmony output is:

Inflating 10 bytes in a loop... [ 10 ] ...read total 10 bytes
Inflating 5 bytes in a loop... [ 5 ] ...read total 5 bytes
Inflating 0 bytes in a loop... [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ... forever



> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Priority: Critical
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison reassigned HARMONY-6637:
------------------------------------

    Assignee: Tim Ellison

> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Ellison resolved HARMONY-6637.
----------------------------------

    Fix Version/s: 5.0M16
       Resolution: Fixed

Fix and regression test added to the ARCHIVE module at repo revision r1003513.

Roberto, please check that it resolves the problem satisfactorily for you.


> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M16
>
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Posted by "Roberto Tyley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918921#action_12918921 ] 

Roberto Tyley commented on HARMONY-6637:
----------------------------------------

Thanks, that's fantastic - I ran my codebase against the relevant Hudson snapshot builds (harmony-5.0-jdk-1003286 vs harmony-5.0-jdk-1003526 before/after the fix) and have confirmed that the new build resolves my problems.

much appreciated,
Roberto




> [classlib] [archive] Inflater.inflate() short-circuits on zero-length request, finished() never true for a zero-length data source
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6637
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6637
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Roberto Tyley
>            Assignee: Tim Ellison
>            Priority: Critical
>             Fix For: 5.0M16
>
>         Attachments: Main.java
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.