Changeset 32642 in osm for applications


Ignore:
Timestamp:
2016-07-12T17:28:07+02:00 (8 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.

Location:
applications/editors/josm/plugins/mapillary
Files:
1 added
2 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      }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/ImageUtilsTest.java

    r32593 r32642  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertTrue;
    67
     
    9192  }
    9293
     94  @Test
     95  public void testFileFilterAgainstEmptyFile() throws URISyntaxException {
     96    File f = new File(ImageUtil.class.getResource("/zeroByteFile").toURI());
     97    assertFalse(ImageUtil.IMAGE_FILE_FILTER.accept(f));
     98  }
     99
    93100}
Note: See TracChangeset for help on using the changeset viewer.