jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java
changeset 42749 91fb907a8732
parent 42188 471f232f8ea8
child 43317 cbe67e782fce
equal deleted inserted replaced
42748:fca460b63839 42749:91fb907a8732
   539             }
   539             }
   540         }
   540         }
   541     }
   541     }
   542 
   542 
   543     // Stream position initially at beginning, left at end
   543     // Stream position initially at beginning, left at end
   544     // if ignoreUnknownFields is true, do not load fields for which
   544     // if readUnknownTags is false, do not load fields for which
   545     // a tag cannot be found in an allowed TagSet.
   545     // a tag cannot be found in an allowed TagSet.
   546     public void initialize(ImageInputStream stream, boolean isPrimaryIFD,
   546     public void initialize(ImageInputStream stream, boolean isPrimaryIFD,
   547         boolean ignoreUnknownFields) throws IOException {
   547         boolean ignoreMetadata, boolean readUnknownTags) throws IOException {
   548 
   548 
   549         removeTIFFFields();
   549         removeTIFFFields();
   550 
   550 
   551         long streamLength = stream.length();
   551         long streamLength = stream.length();
   552         boolean haveStreamLength = streamLength != -1;
   552         boolean haveStreamLength = streamLength != -1;
   553 
   553 
   554         List<TIFFTagSet> tagSetList = getTagSetList();
   554         List<TIFFTagSet> tagSetList = getTagSetList();
   555 
   555 
       
   556         // Configure essential tag variables if this is the primary IFD and
       
   557         // either all metadata are being ignored, or metadata are not being
       
   558         // ignored but both unknown tags are being ignored and the tag set
       
   559         // list does not contain the baseline tags.
   556         boolean ensureEssentialTags = false;
   560         boolean ensureEssentialTags = false;
   557         TIFFTagSet baselineTagSet = null;
   561         TIFFTagSet baselineTagSet = null;
   558         if (isPrimaryIFD && ignoreUnknownFields
   562         if (isPrimaryIFD &&
   559             && !tagSetList.contains(BaselineTIFFTagSet.getInstance())) {
   563             (ignoreMetadata ||
       
   564              (!readUnknownTags &&
       
   565               !tagSetList.contains(BaselineTIFFTagSet.getInstance())))) {
   560             ensureEssentialTags = true;
   566             ensureEssentialTags = true;
   561             initializeEssentialTags();
   567             initializeEssentialTags();
   562             baselineTagSet = BaselineTIFFTagSet.getInstance();
   568             baselineTagSet = BaselineTIFFTagSet.getInstance();
   563         }
   569         }
   564 
   570 
   588             if (tag == null && ensureEssentialTags
   594             if (tag == null && ensureEssentialTags
   589                 && essentialTags.contains(tagNumber)) {
   595                 && essentialTags.contains(tagNumber)) {
   590                 tag = baselineTagSet.getTag(tagNumber);
   596                 tag = baselineTagSet.getTag(tagNumber);
   591             }
   597             }
   592 
   598 
   593             // Ignore unknown fields, fields with unknown type, and fields
   599             // Ignore non-essential fields, unknown fields unless forcibly
       
   600             // being read, fields with unknown type, and fields
   594             // with count out of int range.
   601             // with count out of int range.
   595             if((tag == null && ignoreUnknownFields)
   602             if((ignoreMetadata &&
       
   603                 (!ensureEssentialTags || !essentialTags.contains(tagNumber)))
       
   604                 || (tag == null && !readUnknownTags)
   596                 || (tag != null && !tag.isDataTypeOK(type))
   605                 || (tag != null && !tag.isDataTypeOK(type))
   597                 || longCount > Integer.MAX_VALUE) {
   606                 || longCount > Integer.MAX_VALUE) {
   598                 // Skip the value/offset so as to leave the stream
   607                 // Skip the value/offset so as to leave the stream
   599                 // position at the start of the next IFD entry.
   608                 // position at the start of the next IFD entry.
   600                 stream.skipBytes(4);
   609                 stream.skipBytes(4);
   699                 if (tag.isIFDPointer()) {
   708                 if (tag.isIFDPointer()) {
   700                     List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
   709                     List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
   701                     tagSets.add(tag.getTagSet());
   710                     tagSets.add(tag.getTagSet());
   702                     TIFFIFD subIFD = new TIFFIFD(tagSets);
   711                     TIFFIFD subIFD = new TIFFIFD(tagSets);
   703 
   712 
   704                     subIFD.initialize(stream, false, ignoreUnknownFields);
   713                     subIFD.initialize(stream, false, ignoreMetadata,
       
   714                                       readUnknownTags);
   705                     TIFFField f = new TIFFField(tag, type, e.offset, subIFD);
   715                     TIFFField f = new TIFFField(tag, type, e.offset, subIFD);
   706                     addTIFFField(f);
   716                     addTIFFField(f);
   707                 } else {
   717                 } else {
   708                     if (tagNumber == BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS
   718                     if (tagNumber == BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS
   709                             || tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS
   719                             || tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS