Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netcdf: segmentation fault when creating a file in a non-existing directory #11918

Closed
rouault opened this issue Jun 23, 2022 · 8 comments · Fixed by #11920
Closed

netcdf: segmentation fault when creating a file in a non-existing directory #11918

rouault opened this issue Jun 23, 2022 · 8 comments · Fixed by #11920

Comments

@rouault
Copy link
Contributor

rouault commented Jun 23, 2022

This is a regression due to the update to 4.9.0 done in #11879. Previous 4.8.1-4 package errors out cleanly. Issue found on the GDAL autotest continuous integration (cf OSGeo/gdal#5970)

$ nccopy --version
[...]
netCDF library version 4.9.0 of Jun 21 2022 18:22:22 $
$ nccopy byte_no_cf.nc "\non_existing_path\out.nc"
Error:NCpathcvt: stat=-36 (NetCDF: Invalid argument)
Segmentation fault

where byte_no_cf.nc is in the attached zip (but true for any netCDF file).
byte_no_cf.nc.zip

vs

$ nccopy --version
[...]
netCDF library version 4.8.1 of Apr  2 2022 18:28:59 $
$ nccopy byte_no_cf.nc "\non_existing_path\out.nc"
No such file or directory
Location: file ; line 2016
@Biswa96
Copy link
Member

Biswa96 commented Jun 23, 2022

@mjwoods Would you like to provide any information about this issue?

@mmuetzel
Copy link
Collaborator

Is hopefully fixed with PR #11920.
@rouault: Could you please check with the build artifacts from that PR (when they are ready) whether that resolves the error for you?
Should be available here (if building is successful):
https://github.com/msys2/MINGW-packages/actions/runs/2550818176

@rouault
Copy link
Contributor Author

rouault commented Jun 23, 2022

Could you please check with the build artifacts from that PR (when they are ready) whether that resolves the error for you?

Thanks for prompt action. I confirm that mingw-w64-x86_64-netcdf-4.9.0-2-any.pkg.tar.zst fixes the issue. I assume you're going to forward upstream the patch ?

Another "issue" I found is that upstream netCDF changed again their mind about filename encoding. In netCDF 4.8, filenames were expected to be in UTF-8 (previously was in current ANSI code page). And now with 4.9 they switched back to expected them to be in the current ANSI code page (a side effect or intended consequence of Unidata/netcdf-c#2277 I cannot really say). Sigh... But I'll take it as a "feature" which I've adopted my software to, and I hope they won't change again their mind in 4.10...

@mmuetzel
Copy link
Collaborator

Tried to upstream the change. But they seem to have elaborate requirements for contributions. If you already went through that process, feel free to submit a PR to them.

@rouault
Copy link
Contributor Author

rouault commented Jun 23, 2022

Tried to upstream the change. But they seem to have elaborate requirements for contributions. If you already went through that process, feel free to submit a PR to them.

I've already submited PRs, but don't recall the CLA thing was in place (or maybe I just don't remember). Looking quickly, it seems it is just a matter of clicking on a few buttons to accept the CLA. I could do it if that's not practical for you

@mmuetzel
Copy link
Collaborator

mmuetzel commented Jun 23, 2022

Yes, please do. Those pages don't want to load correctly for me. (And I don't understand why they want to collect my address, phone number, ...)

@rouault
Copy link
Contributor Author

rouault commented Jun 23, 2022

Yes, please do.

hum, I guess I need you to transfer copyright of your contribution to me so I have the legal right to contribute it under the CLA. Just a comment here will do for me :-)

@mmuetzel
Copy link
Collaborator

I thought I already gave the permission with the comments here. But to be completely explicit with no room of doubt:
I don't claim any ownership on that one-liner modifying the code of netcdf.

rouault added a commit to rouault/netcdf-c that referenced this issue Jun 23, 2022
It looks like on some platforms (e.g., MinGW) errno isn't set
when opening a file failed. That combination of a file id <0
and errno still 0 leads to a segmentation fault later on.

A possible solution to avoid that segfault is to set the status
to ENOENT if errno is unexpectedly 0.
That leads to the error ("No such file or directory") that was
reportedly emitted before version 4.9.0.

See also this report downstream: msys2/MINGW-packages#11918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants