[jira] [Created] (IMAGING-88) Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (IMAGING-88) Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error

Gary D. Gregory (Jira)
Craig Kelly created IMAGING-88:
----------------------------------

             Summary: Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error
                 Key: IMAGING-88
                 URL: https://issues.apache.org/jira/browse/IMAGING-88
             Project: Commons Imaging
          Issue Type: Bug
          Components: Format: TIFF
    Affects Versions: 1.0
            Reporter: Craig Kelly


In method lowerBound in the class org.apache.commons.imaging.common.itu_t4.T4AndT6Compression, the binary search loop uses:

int middle = (first + last) >>> 2;

To find a mid-point for the search.  However, the bit-shift is causing a divide by 4.  At best this produces bad results, and at worst causes an infinite loop (which is how I found the error). A simple patch to fix is:

Index: src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
===================================================================
--- src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java (revision 1363019)
+++ src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java (working copy)
@@ -720,7 +720,7 @@
         int first = 0;
         int last = entries.length - 1;
         do {
-            int middle = (first + last) >>> 2;
+            int middle = (first + last) >>> 1; //2;
             if (entries[middle].value.intValue() <= value
                     && ((middle + 1) >= entries.length || value < entries[middle + 1].value
                             .intValue())) {


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (IMAGING-88) Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error

Gary D. Gregory (Jira)

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

Damjan Jovanovic resolved IMAGING-88.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.0

Patch applied to SVN, thank you for your contribution!
               

> Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error
> -----------------------------------------------------------------------------------------------------
>
>                 Key: IMAGING-88
>                 URL: https://issues.apache.org/jira/browse/IMAGING-88
>             Project: Commons Imaging
>          Issue Type: Bug
>          Components: Format: TIFF
>    Affects Versions: 1.0
>            Reporter: Craig Kelly
>             Fix For: 1.0
>
>
> In method lowerBound in the class org.apache.commons.imaging.common.itu_t4.T4AndT6Compression, the binary search loop uses:
> int middle = (first + last) >>> 2;
> To find a mid-point for the search.  However, the bit-shift is causing a divide by 4.  At best this produces bad results, and at worst causes an infinite loop (which is how I found the error). A simple patch to fix is:
> Index: src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
> ===================================================================
> --- src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java (revision 1363019)
> +++ src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java (working copy)
> @@ -720,7 +720,7 @@
>          int first = 0;
>          int last = entries.length - 1;
>          do {
> -            int middle = (first + last) >>> 2;
> +            int middle = (first + last) >>> 1; //2;
>              if (entries[middle].value.intValue() <= value
>                      && ((middle + 1) >= entries.length || value < entries[middle + 1].value
>                              .intValue())) {

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira