From cb161a989d87c378900810c2879f68d8596f543a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Thu, 24 Feb 2022 13:48:11 +0100 Subject: [PATCH] Don't try to open files you are not supposed to. --- .../animl/converter/ChromatogramMagicNumberMatcher.java | 6 +++--- .../animl/converter/MassSpectrumMagicNumberMatcher.java | 6 +++--- .../msd/converter/supplier/animl/io/ChromatogramReader.java | 3 +++ .../msd/converter/supplier/animl/io/MassSpectrumReader.java | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/ChromatogramMagicNumberMatcher.java b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/ChromatogramMagicNumberMatcher.java index 8a5fa6787..fabb6cce6 100644 --- a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/ChromatogramMagicNumberMatcher.java +++ b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/ChromatogramMagicNumberMatcher.java @@ -30,10 +30,10 @@ public class ChromatogramMagicNumberMatcher extends AbstractMagicNumberMatcher i public boolean checkFileFormat(File file) { boolean isValidFormat = false; + if(file.isDirectory() || !checkFileExtension(file, ".animl")) { + return isValidFormat; + } try { - if(!checkFileExtension(file, ".animl")) { - return isValidFormat; - } DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); diff --git a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/MassSpectrumMagicNumberMatcher.java b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/MassSpectrumMagicNumberMatcher.java index ac91afb4b..812ef7969 100644 --- a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/MassSpectrumMagicNumberMatcher.java +++ b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/converter/MassSpectrumMagicNumberMatcher.java @@ -30,10 +30,10 @@ public class MassSpectrumMagicNumberMatcher extends AbstractMagicNumberMatcher i public boolean checkFileFormat(File file) { boolean isValidFormat = false; + if(file.isDirectory() || !checkFileExtension(file, ".animl")) { + return isValidFormat; + } try { - if(!checkFileExtension(file, ".animl")) { - return isValidFormat; - } DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); diff --git a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/ChromatogramReader.java b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/ChromatogramReader.java index 20d0986b5..b7fad1420 100644 --- a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/ChromatogramReader.java +++ b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/ChromatogramReader.java @@ -72,6 +72,9 @@ public class ChromatogramReader extends AbstractChromatogramMSDReader { @Override public IChromatogramMSD read(File file, IProgressMonitor monitor) throws IOException { + if(file.isDirectory() || !file.getName().endsWith(".animl")) { + return null; + } IVendorChromatogram chromatogram = null; try { AnIMLType animl = XmlReader.getAnIML(file); diff --git a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/MassSpectrumReader.java b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/MassSpectrumReader.java index c0373c5a1..3d9cb1d3c 100644 --- a/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/MassSpectrumReader.java +++ b/openchrom/plugins/net.openchrom.msd.converter.supplier.animl/src/net/openchrom/msd/converter/supplier/animl/io/MassSpectrumReader.java @@ -54,6 +54,9 @@ public class MassSpectrumReader extends AbstractMassSpectraReader implements IMa @Override public IMassSpectra read(File file, IProgressMonitor monitor) throws IOException { + if(file.isDirectory() || !file.getName().endsWith(".animl")) { + return null; + } IVendorStandaloneMassSpectrum massSpectrum = null; // try {