tmf: Bug 478578: Add weak binary validation to text trace types
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlTrace.java
index 7da703416d679683728630ae23faff89b906327c..bf3aa668220985c041fd830aa8e8778376f2c8ca 100644 (file)
@@ -38,6 +38,7 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
@@ -546,6 +547,14 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
         if (!file.exists() || !file.isFile() || !file.canRead()) {
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CustomTrace_FileNotFound + ": " + path); //$NON-NLS-1$
         }
+        try {
+            if (!TmfTraceUtils.isText(file)) {
+                return new TraceValidationStatus(0, Activator.PLUGIN_ID);
+            }
+        } catch (IOException e) {
+            Activator.logError("Error validating file: " + path, e); //$NON-NLS-1$
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "IOException validating file: " + path, e); //$NON-NLS-1$
+        }
         try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
             int lineCount = 0;
             long rawPos = 0;
This page took 0.024827 seconds and 5 git commands to generate.