@@ -128,14 +128,14 @@ public void processTiff(@NotNull final RandomAccessReader reader,
128
128
*
129
129
* @param handler the {@link com.drew.imaging.tiff.TiffHandler} that will coordinate processing and accept read values
130
130
* @param reader the {@link com.drew.lang.RandomAccessReader} from which the data should be read
131
- * @param processedGlobalIfdOffsets the set of visited IFD offsets, to avoid revisiting the same IFD in an endless loop
131
+ * @param processedIfdOffsets the set of visited IFD offsets, to avoid revisiting the same IFD in an endless loop
132
132
* @param ifdOffset the offset within <code>reader</code> at which the IFD data starts
133
133
* @param isBigTiff Whether the IFD uses the BigTIFF data format.
134
134
* @throws IOException an error occurred while accessing the required data
135
135
*/
136
136
public static void processIfd (@ NotNull final TiffHandler handler ,
137
137
@ NotNull final RandomAccessReader reader ,
138
- @ NotNull final Set <Integer > processedGlobalIfdOffsets ,
138
+ @ NotNull final Set <Integer > processedIfdOffsets ,
139
139
final int ifdOffset ,
140
140
final boolean isBigTiff ) throws IOException
141
141
{
@@ -166,12 +166,11 @@ public static void processIfd(@NotNull final TiffHandler handler,
166
166
// Check for directories we've already visited to avoid stack overflows when recursive/cyclic directory structures exist.
167
167
// Note that we track these offsets in the global frame, not the reader's local frame.
168
168
int globalIfdOffset = reader .toUnshiftedOffset (ifdOffset );
169
- if (processedGlobalIfdOffsets .contains (Integer .valueOf (globalIfdOffset ))) {
170
- return ;
171
- }
172
169
173
170
// remember that we've visited this directory so that we don't visit it again later
174
- processedGlobalIfdOffsets .add (globalIfdOffset );
171
+ if (!processedIfdOffsets .add (globalIfdOffset )) {
172
+ return ;
173
+ }
175
174
176
175
// Validate IFD offset
177
176
if (ifdOffset >= reader .getLength () || ifdOffset < 0 ) {
@@ -276,13 +275,13 @@ public static void processIfd(@NotNull final TiffHandler handler,
276
275
if (handler .tryEnterSubIfd (tagId )) {
277
276
isIfdPointer = true ;
278
277
long subDirOffset = reader .getUInt32 ((int ) (tagValueOffset + i *4 ));
279
- processIfd (handler , reader , processedGlobalIfdOffsets , (int ) subDirOffset , isBigTiff );
278
+ processIfd (handler , reader , processedIfdOffsets , (int ) subDirOffset , isBigTiff );
280
279
}
281
280
}
282
281
}
283
282
284
283
// If it wasn't an IFD pointer, allow custom tag processing to occur
285
- if (!isIfdPointer && !handler .customProcessTag ((int ) tagValueOffset , processedGlobalIfdOffsets , reader , tagId , (int ) byteCount , isBigTiff )) {
284
+ if (!isIfdPointer && !handler .customProcessTag ((int ) tagValueOffset , processedIfdOffsets , reader , tagId , (int ) byteCount , isBigTiff )) {
286
285
// If no custom processing occurred, process the tag in the standard fashion
287
286
processTag (handler , tagId , (int ) tagValueOffset , (int ) componentCount , formatCode , reader );
288
287
}
@@ -308,7 +307,7 @@ public static void processIfd(@NotNull final TiffHandler handler,
308
307
}
309
308
310
309
if (handler .hasFollowerIfd ()) {
311
- processIfd (handler , reader , processedGlobalIfdOffsets , nextIfdOffset , isBigTiff );
310
+ processIfd (handler , reader , processedIfdOffsets , nextIfdOffset , isBigTiff );
312
311
}
313
312
}
314
313
} finally {
0 commit comments