cv::FileStorage.open() has an error with “Segmentation fault (core dumped)” for Node.js add-on

I have programed the node.js plug-in(add-on) code, which called c++/OpenCV’s cv::FileStorage to open the XML file.
And it is compiled successfully, but ran an error at cv::FileStorage.open(), prompting a message “Segmentation fault (core dumped)”.
As a side note, all my OpenCV’s functional codes except the cv::FileStorage.open() are compiled and run successfully.
Please tell me the reason for cv::FileStorage.open()'s “Segmentation fault"?
And please tell me a good solution for this error.

My environment:
OS: Ubuntu18.04
OpenCV: version4.5.3
Node.js: version node@14.17.6, node-gyp@8.2.0

C++(OpenCV) side program:

cv::FileStorage fs;                                                                            
try{
    puts("Doing fs.open() at try{}.");
    fs.open("./haarcascade_frontalface_alt.xml", cv::FileStorage::READ); // Segmentation fault (core dumped)
}catch(cv::Exception ex)
{
    puts("Catch Exception!!");
}

same advice

please raise an issue with the package’s maintainer,

@Bonsuke , imo there are 3 cases here, to be checked seperately:

  1. file not found: fs.open() should retur false (and that’s it)
  2. file is there, but no valid filestorage object inside: should throw an exception
  3. file is valid: fs.open() returns true

and unfortunately, i cant reproduce the segfault (4.5.5;win10 4.4.0;ubu18)
are you able to debug it, and maybe get a backtrace ?
also, slightly improved testcode:

cv::FileStorage fs;                                                                            
try{
    puts("Doing fs.open() at try{}.");
    bool ok = fs.open("./haarcascade_frontalface_alt.xml", cv::FileStorage::READ); // Segmentation fault (core dumped)
    puts(ok?"ok":"fail");
}catch(cv::Exception ex)
{
    puts("Catch Exception!!");
    puts(ex.what());
}

perhaps you can point us to some repo, where the “real life” variant is ?

Thank you.
I hope a correct OpenCV REPO source for latest Node.js.version.

Thank you for your suggestion.
I have tried these. As a result,
1.
In the cas of with wrong file name(namely file not exists), program process has reached to “puts(ok?“ok”:“fail”);” with response “fail”.
But not reached to “catch(cv::Exception ex)”.
2.
In the case of with correct file name(namely file exists), program process has reached to “puts(“Doing fs.open() at try{}.”);”
and has failed at fs.open(). That is, never reach to “puts(ok?“ok”:“fail”);” and also never to “catch(cv::Exception ex)”.

By the way, a certain Post(*1) pointed out the version differences of Node.js about these “cv::FileStorage Segmentation fault”.
That is, running in node V12.18.2 is ok, but has an error in node V14.19.0.
So I have upgraded Node.js version to Node.js v16.15.1(LTS), But as usual I have error “Segmentation fault”.

*1 : FileStorage run error in node v14.19.0

i’ll close this, it’s a duplicate of: The request for the fix and improvement of Node.js modules or OpenCV modules about cv::FileStorage()'s “Segmentation fault” - #2 by berak