fix issue 791: validate ncid for classic files

This commit is contained in:
Wei-keng Liao 2018-01-25 00:03:19 -06:00
parent b850482b8e
commit cb7aafa805
2 changed files with 6 additions and 0 deletions

View File

@ -88,6 +88,11 @@ find_in_NCList(int ext_ncid)
unsigned int ncid = ((unsigned int)ext_ncid) >> ID_SHIFT;
if(numfiles > 0 && nc_filelist != NULL && ncid < NCFILELISTLENGTH)
f = nc_filelist[ncid];
/* for classic files, ext_ncid must be a multiple of (1<<ID_SHIFT) */
if (f != NULL && f->model == NC_FORMATX_NC3 && (ext_ncid % (1<<ID_SHIFT)))
return NULL;
return f;
}

View File

@ -49,6 +49,7 @@ main(int argc, char **argv)
/* Create a netcdf-3 file with one dim. */
if (nc_create(FILE_NAME, 0, &ncid)) ERR;
if (nc_def_dim(ncid, LAT_NAME, LAT_LEN, &dimid)) ERR;
if (nc_def_dim(ncid + TEST_VAL_42, LAT_NAME, LAT_LEN, &dimid) != NC_EBADID) ERR;
if (nc_close(ncid)) ERR;
/* Open the file and make sure nc_inq_dimids yeilds correct