浏览代码

Detect invalid content (#458)

Lutz Roeder 5 年之前
父节点
当前提交
5d5616c9c6
共有 2 个文件被更改,包括 8 次插入9 次删除
  1. 5 6
      src/view.js
  2. 3 3
      test/models.json

+ 5 - 6
src/view.js

@@ -1400,20 +1400,19 @@ view.ModelFactoryService = class {
 
     _openSignature(context) {
         const buffer = context.buffer;
-        const identifier = context.identifier;
         if (context.buffer.length === 0) {
             return Promise.reject(new ModelError("File has no content.", true));
         }
         const list = [
-            { name: 'Git LFS', value: 'version https://git-lfs.github.com/spec/v1\n' },
-            { name: 'HTML', value: '<html>' },
-            { name: 'HTML', value: '<!DOCTYPE html>' },
-            { name: 'HTML', value: '\n\n\n\n\n\n<!DOCTYPE html>' }
+            { name: 'Git LFS header', value: 'version https://git-lfs.github.com/spec/v1\n' },
+            { name: 'HTML markup', value: '<html>' },
+            { name: 'HTML markup', value: '<!DOCTYPE html>' },
+            { name: 'HTML markup', value: '\n\n\n\n\n\n<!DOCTYPE html>' }
         ];
         for (const item of list) {
             if (buffer.length >= item.value.length &&
                 buffer.subarray(0, item.value.length).every((v, i) => v === item.value.charCodeAt(i))) {
-                return Promise.reject(new ModelError("Invalid " + item.name + " content in '" + identifier + "'.", true));
+                return Promise.reject(new ModelError("Invalid file content. File contains " + item.name + ".", true));
             }
         }
         return Promise.resolve(context);

+ 3 - 3
test/models.json

@@ -1435,14 +1435,14 @@
     "type":   "coreml",
     "target": "invalid_git_lfs.mlmodel",
     "source": "https://github.com/lutzroeder/netron/files/4432767/invalid_git_lfs.mlmodel.zip[invalid_git_lfs.mlmodel]",
-    "error":  "Invalid Git LFS content in 'invalid_git_lfs.mlmodel'.",
+    "error":  "Invalid file content. File contains Git LFS header.",
     "link":   "https://github.com/lutzroeder/netron/issues/458"
   },
   {
     "type":   "coreml",
     "target": "invalid_html.mlmodel.zip",
     "source": "https://github.com/lutzroeder/netron/files/4432768/invalid_html.mlmodel.zip",
-    "error":  "Invalid HTML content in 'invalid_html.mlmodel.zip'.",
+    "error":  "Invalid file content. File contains HTML markup.",
     "link":   "https://github.com/lutzroeder/netron/issues/458"
   },
   {
@@ -5286,7 +5286,7 @@
     "type":   "tflite",
     "target": "invalid_html.tflite",
     "source": "https://github.com/lutzroeder/netron/files/4432789/invalid_html.tflite.zip[invalid_html.tflite]",
-    "error":  "Invalid HTML content in 'invalid_html.tflite'.",
+    "error":  "Invalid file content. File contains HTML markup.",
     "link":   "https://github.com/lutzroeder/netron/issues/458"
   },
   {