Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-88

Method lowerBound in org.apache.commons.imaging.common.itu_t4.T4AndT6Compression has a division error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-alpha1
    • 1.0-alpha1
    • Format: TIFF
    • None

    Description

      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())) {

      Attachments

        Activity

          People

            Unassigned Unassigned
            craigkelly Craig Kelly
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: