Changeset 2132


Ignore:
Timestamp:
01/19/07 14:10:49 (13 years ago)
Author:
curtis
Message:

Add metadata filtering logic. A metadata entry is filtered out as invalid if
one of the following conditions are met: key or value is null or empty (size
zero), key or value is longer than 8K, key or value do not begin with a
printable character, key does not contain at least one alphabetic character.

Also fixed a bug with ZCT size mismatch detection in testRead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FormatReader.java

    r2131 r2132  
    173173  /** Adds an entry to the metadata table. */ 
    174174  protected void addMeta(String key, Object value) { 
     175    if (key == null || value == null) return; 
     176    if (filterMetadata) { 
     177      // verify key & value are not empty 
     178      if (key.length() == 0) return; 
     179      String val = value.toString(); 
     180      if (val.length() == 0) return; 
     181 
     182      // verify key & value are reasonable length 
     183      int maxLen = 8192; 
     184      if (key.length() > maxLen) return; 
     185      if (val.length() > maxLen) return; 
     186 
     187      // verify key & value start with printable characters 
     188      if (key.charAt(0) < 32) return; 
     189      if (val.charAt(0) < 32) return; 
     190 
     191      // verify key contains at least one alphabetic character 
     192      if (!key.matches(".*[a-zA-Z].*")) return; 
     193    } 
    175194    metadata.put(key, value); 
    176195  } 
     
    635654    reader.setColorTableIgnored(ignoreColors); 
    636655    reader.setNormalized(normalize); 
     656    reader.setMetadataFiltered(true); 
    637657 
    638658    if (!normalize && reader.getPixelType(id) == FLOAT) { 
     
    683703        " (effectively " + effSizeC + ")"); 
    684704      System.out.println("\tSizeT = " + sizeT); 
    685       if (imageCount != sizeZ * sizeC * sizeT / 
    686         ((rgb || (sizeC > 1 && merge)) ? sizeC : 1)) 
    687       { 
     705      if (imageCount != sizeZ * effSizeC * sizeT) { 
    688706        System.out.println("\t************ Warning: ZCT mismatch ************"); 
    689707      } 
Note: See TracChangeset for help on using the changeset viewer.