simplemagic icon indicating copy to clipboard operation
simplemagic copied to clipboard

svg is not recognized

Open Loki-Afro opened this issue 7 years ago • 1 comments

I used this svg file https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg

    @Test
    public void testSvgBug() throws IOException {
        try (InputStream resource = getClass().getResourceAsStream("410.svg")) {
            byte[] byteArray = ByteStreams.toByteArray(resource);
            ContentInfoUtil contentInfoUtil = new ContentInfoUtil();
            ContentInfo match = contentInfoUtil.findMatch(byteArray);
            assertThat(match.getContentType()).isEqualTo(ContentType.SVG);
        }
    }

Seems like there is some issue in the magic.gz file

>>23    search/400      \<svg                   SVG Scalable Vector Graphics image
!:mime  image/svg+xml

well it results in svg is not added to com.j256.simplemagic.entries.MagicEntries#entryList :/

Loki-Afro avatar Oct 26 '18 16:10 Loki-Afro

Confirmed, and this should be relatively easy to detect, as it's an XML file that has "<svg" somewhere in the beginning... It can be either the first tag, or a bit later. However, note that if there is a long comment before the "<svg" tag, and this library reads just a bit of the file, it might just consider it as an XML file...

Looking at how much the library reads, I can see that for various files it reads up to 16KB (test available here by using FilterInputStream class ) , so SVG should usually be possible to detect.

AndroidDeveloperLB avatar Jul 14 '19 18:07 AndroidDeveloperLB