Skip to content

Commit

Permalink
Merge branch 'pr-81'
Browse files Browse the repository at this point in the history
This closes #81
  • Loading branch information
kinow committed Jul 12, 2020
2 parents db76432 + a61676f commit 750dcd9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="1.0-alpha2" date="2020-??-??" description="Second 1.0 alpha release">
<action issue="IMAGING-258" dev="kinow" type="update" due-to="Gary Lucas">
Prevent exception in TIFF when reading EXIF directory
</action>
<action issue="IMAGING-260" dev="kinow" type="update">
Fix mvn site failure with JavaNCSS parse error
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@
*/
package org.apache.commons.imaging.formats.tiff.taginfos;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
import org.apache.commons.imaging.formats.tiff.fieldtypes.FieldType;

/**
* A LONG representing an offset to a TIFF directory.
*/
public class TagInfoDirectory extends TagInfoLong {

private static final List<FieldType> fieldList
= Collections.unmodifiableList(
Arrays.asList(FieldType.LONG, FieldType.IFD));

public TagInfoDirectory(final String name, final int tag,
final TiffDirectoryType directoryType) {
super(name, tag, directoryType, true);
final TiffDirectoryType directoryType) {
super(name, tag, fieldList, 1, directoryType, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.imaging.formats.tiff.taginfos;

import java.nio.ByteOrder;
import java.util.List;

import org.apache.commons.imaging.common.ByteConversions;
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
Expand All @@ -32,6 +33,11 @@ public TagInfoLong(final String name, final int tag, final TiffDirectoryType dir
super(name, tag, FieldType.LONG, 1, directoryType, isOffset);
}

public TagInfoLong(final String name, final int tag, final List<FieldType> dataTypes, final int length,
final TiffDirectoryType exifDirectory, final boolean isOffset) {
super(name, tag, dataTypes, length, exifDirectory, isOffset);
}

public int getValue(final ByteOrder byteOrder, final byte[] bytes) {
return ByteConversions.toInt(bytes, byteOrder);
}
Expand Down
Binary file added src/test/data/images/tiff/10/Imaging258.tiff
Binary file not shown.
3 changes: 3 additions & 0 deletions src/test/data/images/tiff/10/README.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Imaging247 is a copy of the file neutre.TIFF that was supplied by the user for JIRA 247.

Imaging258 is a test file in which an offset field is given as type IFD rather
than type Long.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.List;


import org.apache.commons.imaging.FormatCompliance;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.Imaging;
import org.apache.commons.imaging.common.ImageMetadata;
import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
import org.apache.commons.imaging.internal.Debug;

import org.apache.commons.imaging.formats.tiff.TiffContents;
import org.apache.commons.imaging.formats.tiff.TiffDirectory;
import org.apache.commons.imaging.formats.tiff.TiffReader;

import org.junit.jupiter.api.Test;

public class TiffReadTest extends TiffBaseTest {
Expand All @@ -51,4 +60,27 @@ public void test() throws Exception {
}
}

@Test
public void testReadDirectories() throws Exception {
// same as above, but test reading the TIFF directories
final List<File> images = getTiffImages();
for (final File imageFile : images) {
String name = imageFile.getName();
// the "bad offsets" file will cause an exception to be thrown.
// It's not relevant to what this test is trying to discover.
// So skip it.
if(name.toLowerCase().contains("bad")){
continue;
}
ByteSourceFile byteSource = new ByteSourceFile(imageFile);
HashMap<String, Object> params = new HashMap<>();
TiffReader tiffReader = new TiffReader(true);
TiffContents contents = tiffReader.readDirectories(
byteSource,
true,
FormatCompliance.getDefault());
assertNotNull(contents);
}
}
}

0 comments on commit 750dcd9

Please sign in to comment.