netcdf-c
netcdf-c copied to clipboard
SegV with corrupt netCDF files
netCDF version: 4.8.1 HDF5 version: 1.10.8 OS: Windows 10 & Debian 11 (details below)
I have 2 corrupt netCDF files (file1.nc and file2.nc) which can be accessed in the link here.
I tried to open the files using 'nc_open'. Here is the behavior that I see:
file1.nc
Windows: The process aborts with the following message:
Assertion failed: type == NC_BYTE || type == NC_CHAR || type == NC_SHORT || type == NC_INT || type == NC_FLOAT || type == NC_DOUBLE || type == NC_UBYTE || type == NC_USHORT || type == NC_UINT || type == NC_INT64 || type == NC_UINT64 || type == NC_STRING, file C:\TEMP\batserve\win64\netcdf\libsrc\v1hpg.c, line 212
Debian: The process aborts with a somewhat similar message
/tmp/batserve/B3p1/glnxa64/netcdf/libsrc/v1hpg.c:201: v1h_get_nc_type: Assertion 'type == NC_BYTE || type == NC_CHAR || type == NC_SHORT || type == NC_INT || type == NC_FLOAT || type == NC_DOUBLE || type == NC_UBYTE || type == NC_USHORT || type == NC_UINT || type == NC_INT64 || type == NC_UINT64 || type == NC_STRING' failed. Abort
file2.nc
Windows: The process aborts with the following error message:
Assertion failed: sblock->super_vers >= 2, file C:\TEMP\batserve\win64\hdf5\src\H5Fsuper.c, line 701
Debian: The program exists with error code -33 for nc_open.
For the first 3 cases above where the process aborts, is there any way in which these exceptions can be caught inside the C library and returned as error codes.
#include <stdio.h>
#include <string.h>
#include <netcdf.h>
int
main()
{
int status;
int ncid;
// open the NetCDF-4 file
//status = nc_open("file1.nc", NC_NOWRITE, &ncid);
status = nc_open("file2.nc", NC_NOWRITE, &ncid);
if(status != NC_NOERR) {
printf("Could not open file.\n");
}
// close the file
status = nc_close(ncid);
printf("status after close = %d\n", status);
printf("End of test.\n\n");
return 0;
}
I'll take a look at the code; it is possible that, with logging enabled, it might provide additional information. If not, it seems like there should be a way to get an error instead of a failed assert. In terms of diagnosing what's gone wrong with a netCDF file that has become corrupted, however, there's only so much netCDF will be able to do (beyond adopt friendly failure states) with a file we cannot properly parse. Let me take a look, thanks!
Hello Ward, I was wondering if there was any update regarding this, or if the fix for this has gone into v4.9.1?