Skip to content

dnn: add checks in pooling layer implementation#21336

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:dnn_pooling_check_array_indexes
Dec 24, 2021
Merged

dnn: add checks in pooling layer implementation#21336
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:dnn_pooling_check_array_indexes

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Dec 24, 2021

  • to avoid out of buffer access

relates #19416 (avoid out of range access)

Before (valgrind):

...
[DEBUG:0@5.537] DNN/ONNX: processing node with 1 inputs and 1 outputs: [MaxPool]:(66)
==1070476== Invalid read of size 4
==1070476==    at 0x4AB62B7: cv::dnn::PoolingLayerImpl::getMemoryShapes(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&) const (pooling_layer.cpp:1118)

After:

...
[DEBUG:0@5.778] DNN/ONNX: processing node with 1 inputs and 1 outputs: [MaxPool]:(66)
[ERROR:0@5.824] DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [MaxPool]:(66)
[ INFO:0@5.825]     Input[0] = '65'
[ INFO:0@5.826]     Output[0] = '66'
unknown file: Failure
C++ exception with description "OpenCV(3.4.17-pre) modules/dnn/src/onnx/onnx_importer.cpp:664: error: (-2:Unspecified error) in function 'handleNode'
> Node [MaxPool]:(66) parse error: OpenCV(3.4.17-pre) modules/dnn/src/layers/pooling_layer.cpp:1117: error: (-2:Unspecified error) in function 'virtual bool cv::dnn::PoolingLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const'
> >  (expected: 'addedDims <= inpShape.size()'), where
> >     'addedDims' is 3
> > must be less than or equal to
> >     'inpShape.size()' is 2
> " thrown in the test body.

- to avoid out of buffer access
@alalek
Copy link
Copy Markdown
Member Author

alalek commented Dec 24, 2021

👍

@opencv-pushbot opencv-pushbot merged commit cdd4354 into opencv:3.4 Dec 24, 2021
This was referenced Dec 24, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants