Ignore:
Timestamp:
2016-07-12T17:28:07+02:00 (9 years ago)
Author:
floscher
Message:

Fix NegativeArraySizeException in ImageUtil.ImageFileFilter

This was reported as https://josm.openstreetmap.de/ticket/13096 .
The fix is accompanied by a testcase to prevent future regressions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/ImageUtil.java

    r32374 r32642  
    146146      try (FileInputStream fis = new FileInputStream(f)) {
    147147        int numBytes = fis.read(magic);
    148         return Arrays.equals(JFIF_MAGIC, Arrays.copyOf(magic, Math.min(numBytes, JFIF_MAGIC.length)))
    149             || Arrays.equals(PNG_MAGIC, Arrays.copyOf(magic, Math.min(numBytes, PNG_MAGIC.length)));
     148        return numBytes >= 0 && (
     149          Arrays.equals(JFIF_MAGIC, Arrays.copyOf(magic, Math.min(numBytes, JFIF_MAGIC.length)))
     150          || Arrays.equals(PNG_MAGIC, Arrays.copyOf(magic, Math.min(numBytes, PNG_MAGIC.length)))
     151        );
    150152      } catch (FileNotFoundException e) {
    151153        return false;
    152154      } catch (IOException e) {
     155        Main.warn("IO-exception while reading file "+f.getAbsolutePath());
    153156        return false;
    154157      }
Note: See TracChangeset for help on using the changeset viewer.