ECC-1494: Segmentation fault: 'grib_ls -p values' on several test GRIBs

This commit is contained in:
Shahram Najm 2022-12-15 14:07:03 +00:00
parent 9fe0b53373
commit 418ec30086
4 changed files with 12 additions and 0 deletions

View File

@ -409,6 +409,9 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len)
if (ret)
return ret;
if (*len < (size_t)numberOfValues)
return GRIB_ARRAY_TOO_SMALL;
if ((ret = grib_get_long_internal(handle, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
return ret;

View File

@ -260,6 +260,9 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len)
&numberOfSecondOrderPackedValues)) != GRIB_SUCCESS)
return ret;
if (*len < (size_t)numberOfSecondOrderPackedValues)
return GRIB_ARRAY_TOO_SMALL;
groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups);
groupWidthsSize = numberOfGroups;
if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS)

View File

@ -411,6 +411,9 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len)
for (i = 0; i < numberOfGroups; i++)
n += numbersPerRow[i];
if (*len < (size_t)n)
return GRIB_ARRAY_TOO_SMALL;
X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * n);
n = 0;
k = 0;

View File

@ -501,6 +501,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
if (err)
return err;
if (*len < (size_t)n_vals)
return GRIB_ARRAY_TOO_SMALL;
if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS)