Skip to content

SegV with corrupt netCDF files #2436

@abhibaruah

Description

@abhibaruah

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;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions