-
Bug
-
Resolution: Fixed
-
P4
-
1.2.1
The getMatrix method attempts to protect its internal copy of the matrix
by cloning the array it returns. Unfortunately it performs a shallow clone
of just the top level array and does not clone the member arrays representing
the rows of the matrix. This would allow the caller to be able to modify the
data in the arrays and have those modifications affect the internal data.
Additionally, the returned matrix has one additional row compared to the
matrix that the object was constructed from. This extra row could interfere
with constructing a new BandCombineOp from the matrix of an older one - the
newer instance will have an extra column and thus it will only work on
Rasters with one more band than the original.
----- test case -----
import java.awt.image.BandCombineOp;
public class GetMatrixClone {
public static void main(String argv[]) {
float matrix1[][] = {
{ 1f, 0f, 0f },
{ 0f, 1f, 0f },
{ 0f, 0f, 1f },
};
BandCombineOp bco = new BandCombineOp(matrix1, null);
float matrix2[][] = bco.getMatrix();
testDifferent(matrix1, matrix2, "initial get");
float matrix3[][] = bco.getMatrix();
testDifferent(matrix1, matrix3, "second get");
testDifferent(matrix2, matrix3, "get-to-get");
}
public static void testDifferent(float matrix1[][], float matrix2[][],
String opname)
{
if (matrix1 == matrix2) {
System.err.println(opname+": matrices are identical");
}
for (int i = 0; i < matrix1.length; i++) {
if (matrix1[i] == matrix2[i]) {
System.err.println(opname+": rows "+i+" are identical");
}
if (matrix1[i].length != matrix2[i].length) {
System.err.println(opname+": rows "+i+" are different length");
}
}
}
}
by cloning the array it returns. Unfortunately it performs a shallow clone
of just the top level array and does not clone the member arrays representing
the rows of the matrix. This would allow the caller to be able to modify the
data in the arrays and have those modifications affect the internal data.
Additionally, the returned matrix has one additional row compared to the
matrix that the object was constructed from. This extra row could interfere
with constructing a new BandCombineOp from the matrix of an older one - the
newer instance will have an extra column and thus it will only work on
Rasters with one more band than the original.
----- test case -----
import java.awt.image.BandCombineOp;
public class GetMatrixClone {
public static void main(String argv[]) {
float matrix1[][] = {
{ 1f, 0f, 0f },
{ 0f, 1f, 0f },
{ 0f, 0f, 1f },
};
BandCombineOp bco = new BandCombineOp(matrix1, null);
float matrix2[][] = bco.getMatrix();
testDifferent(matrix1, matrix2, "initial get");
float matrix3[][] = bco.getMatrix();
testDifferent(matrix1, matrix3, "second get");
testDifferent(matrix2, matrix3, "get-to-get");
}
public static void testDifferent(float matrix1[][], float matrix2[][],
String opname)
{
if (matrix1 == matrix2) {
System.err.println(opname+": matrices are identical");
}
for (int i = 0; i < matrix1.length; i++) {
if (matrix1[i] == matrix2[i]) {
System.err.println(opname+": rows "+i+" are identical");
}
if (matrix1[i].length != matrix2[i].length) {
System.err.println(opname+": rows "+i+" are different length");
}
}
}
}