Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
b8cefff4
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
7
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b8cefff4
编写于
6月 23, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 23, 2020
浏览文件
操作
浏览文件
下载
差异文件
!337 add null byte check in the api of get_plugins
Merge pull request !337 from wangshuide/wsd_fuzz_fix
上级
f5c93f29
0fad2218
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
61 addition
and
24 deletion
+61
-24
mindinsight/datavisual/common/exceptions.py
mindinsight/datavisual/common/exceptions.py
+9
-0
mindinsight/datavisual/data_transform/summary_watcher.py
mindinsight/datavisual/data_transform/summary_watcher.py
+4
-22
mindinsight/datavisual/processors/train_task_manager.py
mindinsight/datavisual/processors/train_task_manager.py
+4
-0
mindinsight/datavisual/utils/utils.py
mindinsight/datavisual/utils/utils.py
+21
-0
mindinsight/utils/constant.py
mindinsight/utils/constant.py
+1
-0
tests/st/func/datavisual/taskmanager/test_plugins_restful_api.py
...t/func/datavisual/taskmanager/test_plugins_restful_api.py
+22
-2
未找到文件。
mindinsight/datavisual/common/exceptions.py
浏览文件 @
b8cefff4
...
...
@@ -107,6 +107,15 @@ class TrainJobNotExistError(MindInsightException):
http_code
=
400
)
class
QueryStringContainsNullByteError
(
MindInsightException
):
"""Query string contains null byte error."""
def
__init__
(
self
,
error_detail
):
error_msg
=
f
"Query string contains null byte error. Detail:
{
error_detail
}
"
super
(
QueryStringContainsNullByteError
,
self
).
__init__
(
DataVisualErrors
.
QUERY_STRING_CONTAINS_NULL_BYTE
,
error_msg
,
http_code
=
400
)
class
PluginNotAvailableError
(
MindInsightException
):
"""The given plugin is not available."""
def
__init__
(
self
,
error_detail
):
...
...
mindinsight/datavisual/data_transform/summary_watcher.py
浏览文件 @
b8cefff4
...
...
@@ -22,6 +22,7 @@ from pathlib import Path
from
mindinsight.datavisual.common.log
import
logger
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.utils.tools
import
Counter
from
mindinsight.datavisual.utils.utils
import
contains_null_byte
from
mindinsight.datavisual.common.exceptions
import
MaxCountExceededError
from
mindinsight.utils.exceptions
import
FileSystemPermissionError
...
...
@@ -61,7 +62,7 @@ class SummaryWatcher:
>>> summary_watcher = SummaryWatcher()
>>> directories = summary_watcher.list_summary_directories('/summary/base/dir')
"""
if
self
.
_
contains_null_byte
(
summary_base_dir
=
summary_base_dir
):
if
contains_null_byte
(
summary_base_dir
=
summary_base_dir
):
return
[]
relative_path
=
os
.
path
.
join
(
'.'
,
''
)
...
...
@@ -148,25 +149,6 @@ class SummaryWatcher:
pass
self
.
_update_summary_dict
(
summary_dict
,
summary_base_dir
,
subdir_relative_path
,
subdir_entry
)
def
_contains_null_byte
(
self
,
**
kwargs
):
"""
Check if arg contains null byte.
Args:
kwargs (Any): Check if arg contains null byte.
Returns:
bool, indicates if any arg contains null byte.
"""
for
key
,
value
in
kwargs
.
items
():
if
not
isinstance
(
value
,
str
):
continue
if
'
\x00
'
in
value
:
logger
.
warning
(
'%s contains null byte
\\
x00.'
,
key
)
return
True
return
False
def
_is_valid_summary_directory
(
self
,
summary_base_dir
,
relative_path
):
"""
Check if the given summary directory is valid.
...
...
@@ -276,7 +258,7 @@ class SummaryWatcher:
>>> summary_watcher = SummaryWatcher()
>>> summaries = summary_watcher.is_summary_directory('/summary/base/dir', './job-01')
"""
if
self
.
_
contains_null_byte
(
summary_base_dir
=
summary_base_dir
,
relative_path
=
relative_path
):
if
contains_null_byte
(
summary_base_dir
=
summary_base_dir
,
relative_path
=
relative_path
):
return
False
if
not
self
.
_is_valid_summary_directory
(
summary_base_dir
,
relative_path
):
...
...
@@ -371,7 +353,7 @@ class SummaryWatcher:
>>> summary_watcher = SummaryWatcher()
>>> summaries = summary_watcher.list_summaries('/summary/base/dir', './job-01')
"""
if
self
.
_
contains_null_byte
(
summary_base_dir
=
summary_base_dir
,
relative_path
=
relative_path
):
if
contains_null_byte
(
summary_base_dir
=
summary_base_dir
,
relative_path
=
relative_path
):
return
[]
if
not
self
.
_is_valid_summary_directory
(
summary_base_dir
,
relative_path
):
...
...
mindinsight/datavisual/processors/train_task_manager.py
浏览文件 @
b8cefff4
...
...
@@ -19,7 +19,9 @@ from mindinsight.datavisual.common.log import logger
from
mindinsight.datavisual.common
import
exceptions
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.enums
import
CacheStatus
from
mindinsight.datavisual.common.exceptions
import
QueryStringContainsNullByteError
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.utils.utils
import
contains_null_byte
from
mindinsight.datavisual.processors.base_processor
import
BaseProcessor
from
mindinsight.datavisual.data_transform.data_manager
import
DATAVISUAL_PLUGIN_KEY
,
DATAVISUAL_CACHE_KEY
...
...
@@ -57,6 +59,8 @@ class TrainTaskManager(BaseProcessor):
dict, refer to restful api.
"""
Validation
.
check_param_empty
(
train_id
=
train_id
)
if
contains_null_byte
(
train_id
=
train_id
):
raise
QueryStringContainsNullByteError
(
"train job id: {} contains null byte."
.
format
(
train_id
))
if
manual_update
:
self
.
_data_manager
.
cache_train_job
(
train_id
)
...
...
mindinsight/datavisual/utils/utils.py
浏览文件 @
b8cefff4
...
...
@@ -14,6 +14,7 @@
# ============================================================================
"""Utils."""
import
math
from
mindinsight.datavisual.common.log
import
logger
def
calc_histogram_bins
(
count
):
...
...
@@ -45,3 +46,23 @@ def calc_histogram_bins(count):
return
math
.
ceil
(
count
/
number_per_bucket
)
+
1
return
max_bins
def
contains_null_byte
(
**
kwargs
):
"""
Check if arg contains null byte.
Args:
kwargs (Any): Check if arg contains null byte.
Returns:
bool, indicates if any arg contains null byte.
"""
for
key
,
value
in
kwargs
.
items
():
if
not
isinstance
(
value
,
str
):
continue
if
'
\x00
'
in
value
:
logger
.
warning
(
'%s contains null byte
\\
x00.'
,
key
)
return
True
return
False
mindinsight/utils/constant.py
浏览文件 @
b8cefff4
...
...
@@ -70,6 +70,7 @@ class DataVisualErrors(Enum):
SCALAR_NOT_EXIST
=
14
HISTOGRAM_NOT_EXIST
=
15
TRAIN_JOB_DETAIL_NOT_IN_CACHE
=
16
QUERY_STRING_CONTAINS_NULL_BYTE
=
17
class
ScriptConverterErrors
(
Enum
):
...
...
tests/st/func/datavisual/taskmanager/test_plugins_restful_api.py
浏览文件 @
b8cefff4
...
...
@@ -79,9 +79,9 @@ class TestPlugins:
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
usefixtures
(
"init_summary_logs"
)
@
pytest
.
mark
.
parametrize
(
"train_id"
,
[
"@#$"
,
"./
\x00
home"
,
"./
.//not_exist_id"
,
dict
()])
@
pytest
.
mark
.
parametrize
(
"train_id"
,
[
"@#$"
,
"././/not_exist_id"
,
dict
()])
def
test_plugins_with_special_train_id
(
self
,
client
,
train_id
):
"""Test passing train_id with special character,
null_byte,
invalid id, and wrong type."""
"""Test passing train_id with special character, invalid id, and wrong type."""
params
=
dict
(
train_id
=
train_id
)
url
=
get_url
(
BASE_URL
,
params
)
...
...
@@ -92,6 +92,26 @@ class TestPlugins:
assert
response
[
'error_code'
]
==
'50545005'
assert
response
[
'error_msg'
]
==
"Train job is not exist. Detail: Can not find the train job in data manager."
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
@
pytest
.
mark
.
platform_x86_cpu
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_gpu_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
usefixtures
(
"init_summary_logs"
)
@
pytest
.
mark
.
parametrize
(
"train_id"
,
[
"./
\x00
home"
])
def
test_plugins_with_null_byte_train_id
(
self
,
client
,
train_id
):
"""Test passing train_id with null_byte."""
params
=
dict
(
train_id
=
train_id
,
manual_update
=
True
)
url
=
get_url
(
BASE_URL
,
params
)
response
=
client
.
get
(
url
)
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'50545011'
assert
"Query string contains null byte error. "
in
response
[
'error_msg'
]
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
@
pytest
.
mark
.
platform_x86_cpu
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录