Fix array bounds access in reset_deeper_qualifiers by passing in number of elements

This commit is contained in:
Shahram Najm 2018-01-08 13:38:46 +00:00
parent 71b3545368
commit 7b8a4f4f31
1 changed files with 10 additions and 8 deletions

View File

@ -1773,10 +1773,12 @@ static GRIB_INLINE int significanceQualifierIndex(int X,int Y)
} }
static GRIB_INLINE void reset_deeper_qualifiers( static GRIB_INLINE void reset_deeper_qualifiers(
grib_accessor* significanceQualifierGroup[], const int* const significanceQualifierDepth, int depth) grib_accessor* significanceQualifierGroup[],
const int* const significanceQualifierDepth,
int numElements, int depth)
{ {
int i; int i;
for (i=0;i<number_of_qualifiers;i++) { for (i=0;i<numElements;i++) {
if (significanceQualifierDepth[i]>depth) { if (significanceQualifierDepth[i]>depth) {
significanceQualifierGroup[i]=0; significanceQualifierGroup[i]=0;
} }
@ -2045,7 +2047,8 @@ static int create_keys(grib_accessor* a,long onlySubset,long startSubset,long en
depth=significanceQualifierDepth[sidx]; depth=significanceQualifierDepth[sidx];
if (depth < max_depth) { if (depth < max_depth) {
/* If depth >= max_depth, then no entry will be deeper so no need for call */ /* If depth >= max_depth, then no entry will be deeper so no need for call */
reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,
number_of_qualifiers,depth);
} }
} else { } else {
/* if (forceGroupClosure) { */ /* if (forceGroupClosure) { */
@ -2091,11 +2094,10 @@ static int create_keys(grib_accessor* a,long onlySubset,long startSubset,long en
if (bitmapGroup[bitmapIndex]) { if (bitmapGroup[bitmapIndex]) {
groupSection=bitmapGroup[bitmapIndex]->parent; groupSection=bitmapGroup[bitmapIndex]->parent;
depth=bitmapDepth[bitmapIndex]; depth=bitmapDepth[bitmapIndex];
reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,
/* TODO: This branch is not reached in our tests! could cause problems!! number_of_qualifiers,depth);
* Should pass in number of elements of group/depth arrays and not assume 'number_of_qualifiers'! /* TODO: This branch is not reached in our tests! */
*/ reset_deeper_qualifiers(bitmapGroup,bitmapDepth,MAX_NUMBER_OF_BITMAPS,depth);
reset_deeper_qualifiers(bitmapGroup,bitmapDepth,depth);
} else { } else {
groupSection=section; groupSection=section;
depth++; depth++;