Skip to content

Commit 6f1294b

Browse files
committed
CVS-182188 Out-of-bounds Read in ONNX QLinearConcat Converter Stride-3 Loop leads to Crash / DoS
- Fixed by tightening inputs count validation - Unit tested
1 parent 19e5868 commit 6f1294b

File tree

4 files changed

+193
-2
lines changed

4 files changed

+193
-2
lines changed

src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_concat.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ namespace com_microsoft {
2323
namespace opset_1 {
2424

2525
ov::OutputVector qlinear_concat(const ov::frontend::onnx::Node& node) {
26-
common::default_op_checks(node, 3);
27-
2826
auto inputs = node.get_ov_inputs();
27+
FRONT_END_OP_CONVERSION_CHECK(inputs.size() >= 5 && (inputs.size() - 2) % 3 == 0,
28+
"QLinearConcat: expected 2 + 3*N inputs (Y_scale, Y_zero_point, and N groups of "
29+
"(X, X_scale, X_zero_point)), got: ",
30+
inputs.size());
31+
2932
auto Y_scale = inputs[0];
3033
auto Y_zero_point =
3134
ov::op::util::is_null(inputs[1]) ? v0::Constant::create(Y_scale.get_element_type(), {}, {0}) : inputs[1];

src/frontends/onnx/tests/convert_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@ TEST(ONNXFeConvertException, exception_if_both_unsupported_onnx_validation_excep
6060
ov::AssertFailure,
6161
testing::HasSubstr("only 'DCR' and 'CRD' modes are supported"));
6262
}
63+
64+
/// Tests QLinearConcat conversion with missing X input triplet (X, X_scale, X_zero_point)
65+
/// Has 2 inputs and satisfies the (2 + 3*N) % 3 == 0 condition, but doesn't satisfy the >= 5 condition
66+
TEST(ONNXFeConvertException, exception_if_qlinear_concat_missing_x_input_triplet) {
67+
OV_EXPECT_THROW(convert_model("com.microsoft/qlinear_concat_missing_x_input_triplet.onnx"),
68+
ov::AssertFailure,
69+
testing::AllOf(testing::HasSubstr("expected 2 + 3*N inputs"), testing::HasSubstr(" got: 2")));
70+
}
71+
72+
/// Tests QLinearConcat conversion with incomplete X input triplet (X, X_scale, X_zero_point)
73+
/// Has 6 inputs and satisfies the >= 5 condition, but doesn't satisfy the (2 + 3*N) % 3 == 0 condition
74+
TEST(ONNXFeConvertException, exception_if_qlinear_concat_invalid_x_input_triplet) {
75+
OV_EXPECT_THROW(convert_model("com.microsoft/qlinear_concat_invalid_x_input_triplet.onnx"),
76+
ov::AssertFailure,
77+
testing::AllOf(testing::HasSubstr("expected 2 + 3*N inputs"), testing::HasSubstr(" got: 6")));
78+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
ir_version: 3
2+
producer_name: "OpenVINO ONNX Frontend"
3+
producer_version: ""
4+
model_version: 0
5+
graph {
6+
name: "qlinear_concat_invalid_x_input_triplet"
7+
8+
node {
9+
input: "Y_scale"
10+
input: "Y_zero_point"
11+
input: "X1"
12+
input: "X1_scale"
13+
input: "X1_zero_point"
14+
input: "X2"
15+
output: "Y"
16+
op_type: "QLinearConcat"
17+
attribute {
18+
name: "axis"
19+
i: 0
20+
type: INT
21+
}
22+
domain: "com.microsoft"
23+
}
24+
25+
input {
26+
name: "Y_scale"
27+
type {
28+
tensor_type {
29+
elem_type: 1
30+
shape {
31+
dim { dim_value: 1 }
32+
}
33+
}
34+
}
35+
}
36+
37+
input {
38+
name: "Y_zero_point"
39+
type {
40+
tensor_type {
41+
elem_type: 2
42+
shape {
43+
dim { dim_value: 1 }
44+
}
45+
}
46+
}
47+
}
48+
49+
input {
50+
name: "X1"
51+
type {
52+
tensor_type {
53+
elem_type: 2
54+
shape {
55+
dim { dim_value: 4 }
56+
}
57+
}
58+
}
59+
}
60+
61+
input {
62+
name: "X1_scale"
63+
type {
64+
tensor_type {
65+
elem_type: 2
66+
shape {
67+
dim { dim_value: 4 }
68+
}
69+
}
70+
}
71+
}
72+
73+
input {
74+
name: "X1_zero_point"
75+
type {
76+
tensor_type {
77+
elem_type: 2
78+
shape {
79+
dim { dim_value: 4 }
80+
}
81+
}
82+
}
83+
}
84+
85+
input {
86+
name: "X2"
87+
type {
88+
tensor_type {
89+
elem_type: 2
90+
shape {
91+
dim { dim_value: 4 }
92+
}
93+
}
94+
}
95+
}
96+
97+
output {
98+
name: "Y"
99+
type {
100+
tensor_type {
101+
elem_type: 2
102+
shape {
103+
dim { dim_value: 4 }
104+
}
105+
}
106+
}
107+
}
108+
}
109+
opset_import {
110+
domain: "com.microsoft"
111+
version: 1
112+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ir_version: 3
2+
producer_name: "OpenVINO ONNX Frontend"
3+
producer_version: ""
4+
model_version: 0
5+
graph {
6+
name: "qlinear_concat_missing_x_input_triplet"
7+
8+
node {
9+
input: "Y_scale"
10+
input: "Y_zero_point"
11+
output: "Y"
12+
op_type: "QLinearConcat"
13+
attribute {
14+
name: "axis"
15+
i: 0
16+
type: INT
17+
}
18+
domain: "com.microsoft"
19+
}
20+
21+
input {
22+
name: "Y_scale"
23+
type {
24+
tensor_type {
25+
elem_type: 1
26+
shape {
27+
dim { dim_value: 1 }
28+
}
29+
}
30+
}
31+
}
32+
33+
input {
34+
name: "Y_zero_point"
35+
type {
36+
tensor_type {
37+
elem_type: 2
38+
shape {
39+
dim { dim_value: 1 }
40+
}
41+
}
42+
}
43+
}
44+
45+
output {
46+
name: "Y"
47+
type {
48+
tensor_type {
49+
elem_type: 2
50+
shape {
51+
dim { dim_value: 4 }
52+
}
53+
}
54+
}
55+
}
56+
}
57+
opset_import {
58+
domain: "com.microsoft"
59+
version: 1
60+
}

0 commit comments

Comments
 (0)