1+ #include < gtest/gtest.h>
2+ #include < fstream>
3+ #include < string>
4+ #include < cstdlib>
5+ #include < memory>
6+
7+ extern " C" {
8+ #include " tools/plugin/modules/ov_noise_suppression/noise_suppression_interface.h"
9+ }
10+
11+ class NoiseSuppressionSecurityTest : public ::testing::TestWithParam<std::vector<int64_t >> {};
12+
13+ TEST_P (NoiseSuppressionSecurityTest, TensorShapeValidationMaintainsBounds) {
14+ // Invariant: Model input tensor shapes must not cause memory corruption
15+ // All allocations derived from tensor shapes must be within safe bounds
16+
17+ std::vector<int64_t > dimensions = GetParam ();
18+
19+ // Create a minimal mock model file with specified dimensions
20+ std::string model_path = " /tmp/test_model_" + std::to_string (getpid ()) + " .xml" ;
21+ std::ofstream model_file (model_path);
22+ model_file << " <?xml version=\" 1.0\" ?><net><layers><layer id=\" 0\" name=\" input\" type=\" Parameter\" >" ;
23+ model_file << " <output><port id=\" 0\" precision=\" FP32\" ><dim>" ;
24+ for (size_t i = 0 ; i < dimensions.size (); ++i) {
25+ if (i > 0 ) model_file << " </dim><dim>" ;
26+ model_file << dimensions[i];
27+ }
28+ model_file << " </dim></port></output></layer></layers></net>" ;
29+ model_file.close ();
30+
31+ struct noise_suppression_data *nd = (struct noise_suppression_data *)calloc (1 , sizeof (*nd));
32+ ASSERT_NE (nd, nullptr );
33+
34+ // Attempt to load model - should not crash or corrupt memory
35+ int result = noise_suppression_load_model (nd, model_path.c_str ());
36+
37+ if (result == 0 && nd->inp_shape .size () > 0 ) {
38+ // Verify shape dimensions are within reasonable bounds
39+ for (auto dim : nd->inp_shape ) {
40+ EXPECT_GT (dim, 0 ) << " Dimension must be positive" ;
41+ EXPECT_LT (dim, 1000000 ) << " Dimension exceeds safe allocation limit" ;
42+ }
43+ }
44+
45+ noise_suppression_destroy (nd);
46+ std::remove (model_path.c_str ());
47+ }
48+
49+ INSTANTIATE_TEST_SUITE_P (
50+ AdversarialShapes,
51+ NoiseSuppressionSecurityTest,
52+ ::testing::Values (
53+ std::vector<int64_t >{0x7FFFFFFFFFFFFFFF , 1024 }, // Integer overflow case
54+ std::vector<int64_t >{0 , 0 }, // Zero-size allocation
55+ std::vector<int64_t >{1 , 480 } // Valid input
56+ )
57+ );
58+
59+ int main (int argc, char **argv) {
60+ ::testing::InitGoogleTest (&argc, argv);
61+ return RUN_ALL_TESTS ();
62+ }
0 commit comments