Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wux_labs
Tensorflow
提交
21652514
T
Tensorflow
项目概览
wux_labs
/
Tensorflow
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
21652514
编写于
10月 24, 2022
作者:
A
A. Unique TensorFlower
提交者:
TensorFlower Gardener
10月 24, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix security vulnerability with FractionalMax(AVG)Pool with illegal pooling_ratio
PiperOrigin-RevId: 483486453
上级
d689c198
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
84 addition
and
10 deletion
+84
-10
tensorflow/core/kernels/fractional_avg_pool_op.cc
tensorflow/core/kernels/fractional_avg_pool_op.cc
+11
-3
tensorflow/core/kernels/fractional_max_pool_op.cc
tensorflow/core/kernels/fractional_max_pool_op.cc
+6
-0
tensorflow/core/ops/nn_ops.cc
tensorflow/core/ops/nn_ops.cc
+7
-0
tensorflow/core/ops/nn_ops_test.cc
tensorflow/core/ops/nn_ops_test.cc
+7
-6
tensorflow/python/kernel_tests/nn_ops/fractional_avg_pool_op_test.py
...python/kernel_tests/nn_ops/fractional_avg_pool_op_test.py
+35
-0
tensorflow/python/kernel_tests/nn_ops/fractional_max_pool_op_test.py
...python/kernel_tests/nn_ops/fractional_max_pool_op_test.py
+18
-1
未找到文件。
tensorflow/core/kernels/fractional_avg_pool_op.cc
浏览文件 @
21652514
...
...
@@ -44,6 +44,12 @@ class FractionalAvgPoolOp : public OpKernel {
OP_REQUIRES
(
context
,
pooling_ratio_
.
size
()
==
4
,
errors
::
InvalidArgument
(
"pooling_ratio field must specify 4 dimensions"
));
for
(
std
::
size_t
i
=
0
;
i
<
pooling_ratio_
.
size
();
++
i
)
{
OP_REQUIRES
(
context
,
pooling_ratio_
[
i
]
>=
1
,
errors
::
InvalidArgument
(
"pooling_ratio cannot be smaller than 1, got: "
,
pooling_ratio_
[
i
]));
}
OP_REQUIRES
(
context
,
pooling_ratio_
[
0
]
==
1
||
pooling_ratio_
[
3
]
==
1
,
errors
::
Unimplemented
(
"Fractional average pooling is not yet "
...
...
@@ -82,9 +88,11 @@ class FractionalAvgPoolOp : public OpKernel {
for
(
int
i
=
0
;
i
<
tensor_in_and_out_dims
;
++
i
)
{
input_size
[
i
]
=
tensor_in
.
dim_size
(
i
);
OP_REQUIRES
(
context
,
pooling_ratio_
[
i
]
<=
input_size
[
i
],
errors
::
InvalidArgument
(
"Pooling ratio cannot be bigger than input tensor dim size."
));
context
,
input_size
[
i
]
>=
pooling_ratio_
[
i
],
errors
::
InvalidArgument
(
"Pooling ratio is higher than input "
"dimension size for dimension "
,
i
,
". Input dim size: "
,
input_size
[
i
],
" pooling ratio: "
,
pooling_ratio_
[
i
]));
}
// Output size.
for
(
int
i
=
0
;
i
<
tensor_in_and_out_dims
;
++
i
)
{
...
...
tensorflow/core/kernels/fractional_max_pool_op.cc
浏览文件 @
21652514
...
...
@@ -45,6 +45,12 @@ class FractionalMaxPoolOp : public OpKernel {
OP_REQUIRES
(
context
,
pooling_ratio_
.
size
()
==
4
,
errors
::
InvalidArgument
(
"pooling_ratio field must "
"specify 4 dimensions"
));
for
(
std
::
size_t
i
=
0
;
i
<
pooling_ratio_
.
size
();
++
i
)
{
OP_REQUIRES
(
context
,
pooling_ratio_
[
i
]
>=
1
,
errors
::
InvalidArgument
(
"pooling_ratio cannot be smaller than 1, got: "
,
pooling_ratio_
[
i
]));
}
OP_REQUIRES
(
context
,
pooling_ratio_
[
0
]
==
1
||
pooling_ratio_
[
3
]
==
1
,
...
...
tensorflow/core/ops/nn_ops.cc
浏览文件 @
21652514
...
...
@@ -63,6 +63,13 @@ Status FractionalPoolShapeFn(InferenceContext* c) {
}
}
for
(
std
::
size_t
i
=
0
;
i
<
pooling_ratio
.
size
();
++
i
)
{
if
(
pooling_ratio
[
i
]
<
1
)
{
return
errors
::
InvalidArgument
(
"pooling_ratio cannot be smaller than 1, got: "
,
pooling_ratio
[
i
]);
}
}
c
->
set_output
(
0
,
c
->
MakeShape
(
output_dims
));
c
->
set_output
(
1
,
c
->
Vector
(
output_dims
[
1
]));
c
->
set_output
(
2
,
c
->
Vector
(
output_dims
[
2
]));
...
...
tensorflow/core/ops/nn_ops_test.cc
浏览文件 @
21652514
...
...
@@ -523,7 +523,8 @@ TEST(NNOpsTest, FractionalPool_ShapeFn) {
.
Finalize
(
&
op
.
node_def
));
};
set_op
(
std
::
vector
<
float
>
{
2.0
f
,
1
,
1
/
1.5
f
,
1
/
2.0
f
});
// pooling_ratio must >= 1.0
set_op
(
std
::
vector
<
float
>
{
2.0
f
,
1
,
1.5
f
,
4.0
f
});
// Rank check.
INFER_ERROR
(
"must be rank 4"
,
op
,
"[?,?,?]"
);
...
...
@@ -532,11 +533,11 @@ TEST(NNOpsTest, FractionalPool_ShapeFn) {
INFER_OK
(
op
,
"?"
,
"[?,?,?,?];[?];[?]"
);
INFER_OK
(
op
,
"[?,?,?,?]"
,
"[?,?,?,?];[?];[?]"
);
INFER_OK
(
op
,
"[10,20,30,40]"
,
"[5,20,
45,80];[20];[45
]"
);
INFER_OK
(
op
,
"[?,20,30,40]"
,
"[?,20,
45,80];[20];[45
]"
);
INFER_OK
(
op
,
"[10,?,30,40]"
,
"[5,?,
45,80];[?];[45
]"
);
INFER_OK
(
op
,
"[10,20,?,40]"
,
"[5,20,?,
8
0];[20];[?]"
);
INFER_OK
(
op
,
"[10,20,30,?]"
,
"[5,20,
45,?];[20];[45
]"
);
INFER_OK
(
op
,
"[10,20,30,40]"
,
"[5,20,
20,10];[20];[20
]"
);
INFER_OK
(
op
,
"[?,20,30,40]"
,
"[?,20,
20,10];[20];[20
]"
);
INFER_OK
(
op
,
"[10,?,30,40]"
,
"[5,?,
20,10];[?];[20
]"
);
INFER_OK
(
op
,
"[10,20,?,40]"
,
"[5,20,?,
1
0];[20];[?]"
);
INFER_OK
(
op
,
"[10,20,30,?]"
,
"[5,20,
20,?];[20];[20
]"
);
// Wrong number of values for pooling_ratio.
set_op
(
std
::
vector
<
float
>
{
.5
,
1.0
,
1.5
});
...
...
tensorflow/python/kernel_tests/nn_ops/fractional_avg_pool_op_test.py
浏览文件 @
21652514
...
...
@@ -333,6 +333,41 @@ class FractionalAvgTest(test.TestCase):
self
.
evaluate
(
z
)
def
testPoolingRatioHasMoreDimThanInput
(
self
):
with
self
.
cached_session
()
as
_
:
with
self
.
assertRaisesRegex
(
errors
.
InvalidArgumentError
,
r
"Pooling ratio is higher than input dimension size for dimension 1.*"
):
result
=
nn_ops
.
gen_nn_ops
.
fractional_avg_pool
(
value
=
constant_op
.
constant
(
value
=
[[[[
1
,
4
,
2
,
3
]]]],
dtype
=
dtypes
.
int64
),
pooling_ratio
=
[
1.0
,
1.44
,
1.73
,
1.0
],
pseudo_random
=
False
,
overlapping
=
False
,
deterministic
=
False
,
seed
=
0
,
seed2
=
0
,
name
=
None
)
self
.
evaluate
(
result
)
def
testPoolingRatioValueOutOfRange
(
self
):
with
self
.
cached_session
()
as
_
:
# Whether turn on `TF2_BEHAVIOR` generates different error messages
with
self
.
assertRaisesRegex
(
(
errors
.
InvalidArgumentError
,
ValueError
),
r
"(pooling_ratio cannot be smaller than 1, got: .*)|(is negative)"
):
result
=
nn_ops
.
gen_nn_ops
.
fractional_avg_pool
(
value
=
np
.
zeros
([
3
,
30
,
30
,
3
]),
pooling_ratio
=
[
1
,
-
1
,
3
,
1
],
pseudo_random
=
False
,
overlapping
=
False
,
deterministic
=
False
,
seed
=
0
,
seed2
=
0
,
)
self
.
evaluate
(
result
)
class
FractionalAvgPoolGradTest
(
test
.
TestCase
):
"""Tests for FractionalAvgPoolGrad.
...
...
tensorflow/python/kernel_tests/nn_ops/fractional_max_pool_op_test.py
浏览文件 @
21652514
...
...
@@ -320,7 +320,7 @@ class FractionalMaxPoolTest(test.TestCase):
nn_ops
.
fractional_max_pool
(
rand_mat
,
[
1
,
1.5
,
1.5
,
1
],
seed
=
1
,
seed2
=
1
,
deterministic
=
True
)
def
testPoolingRatio
(
self
):
def
testPoolingRatio
HasMoreDimThanInput
(
self
):
with
self
.
cached_session
()
as
_
:
with
self
.
assertRaisesRegex
(
errors
.
InvalidArgumentError
,
...
...
@@ -338,6 +338,23 @@ class FractionalMaxPoolTest(test.TestCase):
name
=
None
)
self
.
evaluate
(
result
)
def
testPoolingRatioValueOutOfRange
(
self
):
with
self
.
cached_session
()
as
_
:
# Whether turn on `TF2_BEHAVIOR` generates different error messages
with
self
.
assertRaisesRegex
(
(
errors
.
InvalidArgumentError
,
ValueError
),
r
"(pooling_ratio cannot be smaller than 1, got: .*)|(is negative)"
):
result
=
nn_ops
.
gen_nn_ops
.
fractional_max_pool
(
value
=
np
.
zeros
([
3
,
30
,
30
,
3
]),
pooling_ratio
=
[
1
,
-
1
,
3
,
1
],
pseudo_random
=
False
,
overlapping
=
False
,
deterministic
=
False
,
seed
=
0
,
seed2
=
0
,
)
self
.
evaluate
(
result
)
class
FractionalMaxPoolGradTest
(
test
.
TestCase
):
"""Tests for FractionalMaxPoolGrad.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录