< prev index next >

src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java

Print this page

        

*** 261,278 **** * @see TIFFDirectory * @see TIFFTag */ public final class TIFFField implements Cloneable { ! private static final String[] typeNames = { null, "Byte", "Ascii", "Short", "Long", "Rational", "SByte", "Undefined", "SShort", "SLong", "SRational", "Float", "Double", "IFDPointer" }; ! private static final boolean[] isIntegral = { false, true, false, true, true, false, true, true, true, true, false, false, false, false }; --- 261,280 ---- * @see TIFFDirectory * @see TIFFTag */ public final class TIFFField implements Cloneable { ! private static final long MAX_UINT32 = 0xffffffffL; ! ! private static final String[] TYPE_NAMES = { null, "Byte", "Ascii", "Short", "Long", "Rational", "SByte", "Undefined", "SShort", "SLong", "SRational", "Float", "Double", "IFDPointer" }; ! private static final boolean[] IS_INTEGRAL = { false, true, false, true, true, false, true, true, true, true, false, false, false, false };
*** 542,551 **** --- 544,556 ---- * and {@code type} is {@code TIFF_IFD_POINTER}. * @throws NullPointerException if {@code data == null}. * @throws IllegalArgumentException if {@code data} is an instance of * a class incompatible with the specified type. * @throws IllegalArgumentException if the size of the data array is wrong. + * @throws IllegalArgumentException if the type of the data array is + * {@code TIFF_LONG}, {@code TIFF_RATIONAL}, or {@code TIFF_IFD_POINTER} + * and any of the elements is negative or greater than {@code 4294967295}. */ public TIFFField(TIFFTag tag, int type, int count, Object data) { if(tag == null) { throw new NullPointerException("tag == null!"); } else if(type < TIFFTag.MIN_DATATYPE || type > TIFFTag.MAX_DATATYPE) {
*** 585,603 **** && ((char[])data).length == count; break; case TIFFTag.TIFF_LONG: isDataArrayCorrect = data instanceof long[] && ((long[])data).length == count; break; case TIFFTag.TIFF_IFD_POINTER: isDataArrayCorrect = data instanceof long[] && ((long[])data).length == 1; break; case TIFFTag.TIFF_RATIONAL: isDataArrayCorrect = data instanceof long[][] ! && ((long[][])data).length == count ! && ((long[][])data)[0].length == 2; break; case TIFFTag.TIFF_SSHORT: isDataArrayCorrect = data instanceof short[] && ((short[])data).length == count; break; --- 590,643 ---- && ((char[])data).length == count; break; case TIFFTag.TIFF_LONG: isDataArrayCorrect = data instanceof long[] && ((long[])data).length == count; + if (isDataArrayCorrect) { + for (long datum : (long[])data) { + if (datum < 0) { + throw new IllegalArgumentException + ("Negative value supplied for TIFF_LONG"); + } + if (datum > MAX_UINT32) { + throw new IllegalArgumentException + ("Too large value supplied for TIFF_LONG"); + } + } + } break; case TIFFTag.TIFF_IFD_POINTER: isDataArrayCorrect = data instanceof long[] && ((long[])data).length == 1; + if (((long[])data)[0] < 0) { + throw new IllegalArgumentException + ("Negative value supplied for TIFF_IFD_POINTER"); + } + if (((long[])data)[0] > MAX_UINT32) { + throw new IllegalArgumentException + ("Too large value supplied for TIFF_IFD_POINTER"); + } break; case TIFFTag.TIFF_RATIONAL: isDataArrayCorrect = data instanceof long[][] ! && ((long[][])data).length == count; ! if (isDataArrayCorrect) { ! for (long[] datum : (long[][])data) { ! if (datum.length != 2) { ! isDataArrayCorrect = false; ! break; ! } ! if (datum[0] < 0 || datum[1] < 0) { ! throw new IllegalArgumentException ! ("Negative value supplied for TIFF_RATIONAL"); ! } ! if (datum[0] > MAX_UINT32 || datum[1] > MAX_UINT32) { ! throw new IllegalArgumentException ! ("Too large value supplied for TIFF_RATIONAL"); ! } ! } ! } break; case TIFFTag.TIFF_SSHORT: isDataArrayCorrect = data instanceof short[] && ((short[])data).length == count; break;
*** 605,616 **** isDataArrayCorrect = data instanceof int[] && ((int[])data).length == count; break; case TIFFTag.TIFF_SRATIONAL: isDataArrayCorrect = data instanceof int[][] ! && ((int[][])data).length == count ! && ((int[][])data)[0].length == 2; break; case TIFFTag.TIFF_FLOAT: isDataArrayCorrect = data instanceof float[] && ((float[])data).length == count; break; --- 645,663 ---- isDataArrayCorrect = data instanceof int[] && ((int[])data).length == count; break; case TIFFTag.TIFF_SRATIONAL: isDataArrayCorrect = data instanceof int[][] ! && ((int[][])data).length == count; ! if (isDataArrayCorrect) { ! for (int[] datum : (int[][])data) { ! if (datum.length != 2) { ! isDataArrayCorrect = false; ! break; ! } ! } ! } break; case TIFFTag.TIFF_FLOAT: isDataArrayCorrect = data instanceof float[] && ((float[])data).length == count; break;
*** 797,807 **** if (dataType < TIFFTag.MIN_DATATYPE || dataType > TIFFTag.MAX_DATATYPE) { throw new IllegalArgumentException("Unknown data type "+dataType); } ! return typeNames[dataType]; } /** * Returns the data type constant corresponding to the supplied data * type name. If the name is unknown {@code -1} will be returned. --- 844,854 ---- if (dataType < TIFFTag.MIN_DATATYPE || dataType > TIFFTag.MAX_DATATYPE) { throw new IllegalArgumentException("Unknown data type "+dataType); } ! return TYPE_NAMES[dataType]; } /** * Returns the data type constant corresponding to the supplied data * type name. If the name is unknown {@code -1} will be returned.
*** 810,820 **** * @return One of the {@code TIFFTag.TIFF_*} constants or * {@code -1} if the name is not recognized. */ public static int getTypeByName(String typeName) { for (int i = TIFFTag.MIN_DATATYPE; i <= TIFFTag.MAX_DATATYPE; i++) { ! if (typeName.equals(typeNames[i])) { return i; } } return -1; --- 857,867 ---- * @return One of the {@code TIFFTag.TIFF_*} constants or * {@code -1} if the name is not recognized. */ public static int getTypeByName(String typeName) { for (int i = TIFFTag.MIN_DATATYPE; i <= TIFFTag.MAX_DATATYPE; i++) { ! if (typeName.equals(TYPE_NAMES[i])) { return i; } } return -1;
*** 885,895 **** * integral data type. * * @return Whether the field type is integral. */ public boolean isIntegral() { ! return isIntegral[type]; } /** * Returns the number of data items present in the field. For * {@code TIFFTag.TIFF_ASCII} fields, the value returned is the --- 932,942 ---- * integral data type. * * @return Whether the field type is integral. */ public boolean isIntegral() { ! return IS_INTEGRAL[type]; } /** * Returns the number of data items present in the field. For * {@code TIFFTag.TIFF_ASCII} fields, the value returned is the
< prev index next >