Skip to content

Commit cb7aafa

Browse files
committed
fix issue 791: validate ncid for classic files
1 parent b850482 commit cb7aafa

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

libdispatch/nclistmgr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ find_in_NCList(int ext_ncid)
8888
unsigned int ncid = ((unsigned int)ext_ncid) >> ID_SHIFT;
8989
if(numfiles > 0 && nc_filelist != NULL && ncid < NCFILELISTLENGTH)
9090
f = nc_filelist[ncid];
91+
92+
/* for classic files, ext_ncid must be a multiple of (1<<ID_SHIFT) */
93+
if (f != NULL && f->model == NC_FORMATX_NC3 && (ext_ncid % (1<<ID_SHIFT)))
94+
return NULL;
95+
9196
return f;
9297
}
9398

nc_test4/tst_dims.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ main(int argc, char **argv)
4949
/* Create a netcdf-3 file with one dim. */
5050
if (nc_create(FILE_NAME, 0, &ncid)) ERR;
5151
if (nc_def_dim(ncid, LAT_NAME, LAT_LEN, &dimid)) ERR;
52+
if (nc_def_dim(ncid + TEST_VAL_42, LAT_NAME, LAT_LEN, &dimid) != NC_EBADID) ERR;
5253
if (nc_close(ncid)) ERR;
5354

5455
/* Open the file and make sure nc_inq_dimids yeilds correct

0 commit comments

Comments
 (0)