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

nc_open "Abort" crash on a corrupted netCDF classic file #2731

Closed
krisfed opened this issue Aug 8, 2023 · 4 comments · Fixed by #2732
Closed

nc_open "Abort" crash on a corrupted netCDF classic file #2731

krisfed opened this issue Aug 8, 2023 · 4 comments · Fixed by #2732

Comments

@krisfed
Copy link

krisfed commented Aug 8, 2023

Hello netCDF folks!

We are seeing the following crash on a corrupted netcdf file (see nctest_classic_corrupted.nc attached in a ZIP file, nctest_classic_corrupted.nc.zip):

$ ./a.out 
Assertion failed: (extent < X_INT_MAX), function px_get, file posixio.c, line 540.
Abort trap: 6

This is on a mac machine, but we see this crash on all platforms.

Here is the code to reproduce the issue:

#include <iostream>
#include "netcdf.h"

void checkErrorCode(int status, const char* message){
    if (status != NC_NOERR){
        std::cout << "Error code: " << status << " from " << message << std::endl;
        std::cout << nc_strerror(status) << std::endl << std::endl;
    }
}

int main(int argc, const char * argv[]) {
    int ncid;
    int retval;
    
    // open file
    retval = nc_open("nctest_classic_corrupted.nc", NC_NOWRITE, &ncid);
    checkErrorCode(retval, "nc_open");
    
    // close file
    retval = nc_close(ncid);
    checkErrorCode(retval, "nc_close");
    
    return retval;
}

I understand that it makes sense that netCDF functionality does not work on a corrupted file, but it would be nice if a crash could be avoided (even when the file is bad).

We are using netCDF-C v4.9.1.

Thanks in advance for taking a look!

Kris

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue Aug 8, 2023
re: Issue Unidata#2731

A corrupted classic file is causing the library to crash.
Fix so that it returns NC_ENOTNC instead.
@DennisHeimbigner
Copy link
Collaborator

Fixed by PR #2732

@krisfed
Copy link
Author

krisfed commented Aug 11, 2023

Wow, thank you so much for a speedy response and fix, Dennis and Ward!

@krisfed
Copy link
Author

krisfed commented Sep 5, 2023

Thanks again for the super-quick action on this! Wanted to check, is there an approximate timeline for the new netCDF release? Trying to evaluate if we should patch this in our netCDF version now or wait till we can upgrade to the new release that will include this fix.

@WardF
Copy link
Member

WardF commented Sep 5, 2023

No worries and all credit for the fix to @DennisHeimbigner! I don't have a timeline, we are working through some other issues. I'd like to think we will resolve them very quickly but I'd be over-promising. Patching in for now is probably the safest bet :).

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