Skip to content

line detector crashes #1999

@koenbrants

Description

@koenbrants
System information (version)
  • OpenCV => 3.4.5
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2015
Detailed description
  1. Setup the Binary descriptor
  2. call Detect method with data from file attached
    -> Crash due to memory corruption.

look at Method in file binary_descriptor.cpp

int BinaryDescriptor::EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains )

e.g. line 1584 fills in a buffer
.cpp pFirstPartEdgeX_[offsetPFirst] = x; pFirstPartEdgeY_[offsetPFirst++] = y;

The offset keep growing in the while loops, overflowing the allocated memory.
After processing finishes, there is a check (line 2221)
.cpp if( offsetPFirst > edgePixelArraySize || offsetPSecond > edgePixelArraySize ) { std::cout << "Edge drawing Error: The total number of edge pixels is larger than MaxNumOfEdgePixels, " "numofedgePixel1 = " << offsetPFirst << ", numofedgePixel2 = " << offsetPSecond << ", MaxNumOfEdgePixel=" << edgePixelArraySize << std::endl; return -1; }

This check check for a buffer overrun, but the harm has already been done.

Steps to reproduce
```.cpp
  cv::Ptr<cv::line_descriptor::BinaryDescriptor> bd = cv::line_descriptor::BinaryDescriptor::createBinaryDescriptor();

  bd->setNumOfOctaves(1);
  bd->setReductionRatio(2);
  bd->setWidthOfBand(13);

  cv::Mat src = ::imread(cv::String(IMAGE_FILE));
  std::vector<cv::line_descriptor::KeyLine> lines;

  /* extract lines */
  bd->detect(src, lines);
```

testfile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions