Opened 7 years ago

Closed 7 years ago

#6942 closed defect (fixed)

Using H5S_MAX_RANK rather than hard coded 32?

Reported by: Kurt Schwehr Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: svn-trunk
Severity: normal Keywords: netcdf hdf5
Cc:

Description

In r39202, there is mention of 32 and H5S_MAX_RANK. Is it too hard to actually use the H5S_MAX_RANK from H5Spublic.h? e.g.

                    int nDims = CSLCount(papszTokens) - 2;
                    if( nDims >= 32 )
                    {
                        // The number of dimensions in a netCDFv4 file is
                        // limited by #define H5S_MAX_RANK    32
                        // but libnetcdf doesn't check that...
                        CPLDebug("netCDF",
                                 "nc_def_var(%s) failed: too many dimensions",
                                 pszVarName);
                        CSLDestroy(papszTokens);
                        continue;
                    }

Should be something like:

                    int nDims = CSLCount(papszTokens) - 2;
                    if( nDims >= H5S_MAX_RANK )
                    {
                        // The number of dimensions in a netCDFv4 file is
                        // limited by H5S_MAX_RANK,
                        // but libnetcdf doesn't check that...
                        CPLDebug("netCDF",
                                 "nc_def_var(%s) failed: too many dimensions",
                                 pszVarName);
                        CSLDestroy(papszTokens);
                        continue;
                    }

e.g. (UNTESTED!)

  • netcdfdataset.cpp

     
    6060#include "gdal.h"
    6161#include "gdal_frmts.h"
    6262#include "gdal_version.h"
     63#include "hdf5.h"
    6364#include "ogr_core.h"
    6465#include "ogr_srs_api.h"
    6566
     
    58415842#endif
    58425843
    58435844                    int nDims = CSLCount(papszTokens) - 2;
    5844                     if( nDims >= 32 )
     5845                    if( nDims >= H5S_MAX_RANK )
    58455846                    {
    58465847                        // The number of dimensions in a netCDFv4 file is
    5847                         // limited by #define H5S_MAX_RANK    32
    5848                         // but libnetcdf doesn't check that...
     5848                        // limited by H5S_MAX_RANK to 32,
     5849                        // but libnetcdf doesn't check that.
    58495850                        CPLDebug("netCDF",
    58505851                                 "nc_def_var(%s) failed: too many dimensions",
    58515852                                 pszVarName);

Change History (2)

comment:1 by Even Rouault, 7 years ago

Actually, I wanted to make a bug report to libnetcdf. They should validate that and refuse to create variables with more than 32 dimensions for a netCDF v4 file.

comment:2 by Even Rouault, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.