Skip to content

FileStorage segmentation fault when saving to a folder which doesn't exist #21448

@Scratchcat1

Description

@Scratchcat1
System information (version)
  • OpenCV => 4.2.0
  • Operating System / Platform => Ubuntu Mate aarch64
  • Compiler => N/A (Python3)
Detailed description

In Python, when using cv2.FileStorage attempting to save the file to a folder which doesn't exist causes a segmentation fault.

Steps to reproduce
  1. Run the following sample program with the makedirs line commented out.
  2. Segmentation fault occurs

Running the same program with a folder which exists (e.g. uncomment the line to create the folder) works without error.

import cv2
import os

save_folder = os.path.join("work")
save_path = os.path.join(save_folder, f"test_file.yaml")

### Comment the following line out for a segmentation fault
# os.makedirs(save_folder, exist_ok = True)
###

cv_file = cv2.FileStorage(save_path, cv2.FILE_STORAGE_WRITE)
cv_file.write('K', 1)
cv_file.release()
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.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

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions