Skip to content

Usage of uninitialized memory in module alphamat leads to unexpected behavior. #2662

@Sintun

Description

@Sintun
System information (version)
  • OpenCV => 4.4
  • Operating System / Platform => Linux (Kubuntu 18.04.5) 64 Bit
  • Compiler => g++ 8.4.0
Detailed description

In module alphamat: Usage of uninitialized Mat object leads to undefined behavior (segfault) in cm.cpp function lle

Memory allocation without initialization:

Mat Cones(20, 1, DataType<float>::type), Cinv(20, 1, DataType<float>::type);

First usage after declaration and allocation:

Next usage of uninitialized Mat object:

solve(C, Cones, Cinv);

Probable solution

Change


to

Cones = 1;
Remark

I've tested the fix on 23 images and it works for me.

Steps to reproduce

A look at the source code or a run of the example code in valgrind --track-origins=yes.

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

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