Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-alpha1
-
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())) {