Skip to content

FileStorage access segfaults after assignment (assignment operator invalidates object) #17412

@themightyoarfish

Description

@themightyoarfish
System information (version)
  • OpenCV => 4.3.0 (homebrew)
  • Operating System / Platform => macos 10.15
  • Compiler => Clang 10.0.1
Detailed description

When a cv::FileStorage object is assigned, the object cannot be used and causes a segfault with every access.

Steps to reproduce

CMakeLists.txt

find_package(OpenCV 4.0 REQUIRED)
set(CMAKE_CXX_STANDARD 14)
cmake_minimum_required(VERSION 3.15.0)
project(test)
add_executable(test test.cpp)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(test ${OpenCV_LIBRARIES})

test.cpp

#include <iostream>
#include <opencv2/core/persistence.hpp>

int main(int argc, char *argv[]) {
  // crash:
  cv::FileStorage fs;
  fs = cv::FileStorage("test.yml",  cv::FileStorage::READ);
  // no crash
  /* cv::FileStorage fs("test.yml", cv::FileStorage::READ); */
  std::string s;
  fs["string"] >> s;
  std::cout << "read value '" << s << "'" << std::endl;
  return 0;
}

test.yml

%YAML:1.0
string: "wat"

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
    The issue has been raised here, but so far as I can see, no bug report submitted
  • I updated to latest OpenCV version and the issue is still there. I checked with current master, the problem persists.
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions