Crash: setting shapeOfTheEarth=1 but scale factor missing
@@ -141,9 +141,10 @@ static void init(grib_accessor* a,const long l, grib_arguments* c)
{
grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a;
int n = 0;
+ grib_handle* hand = grib_handle_of_accessor(a);
- self->scaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
- self->scaledValue = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
+ self->scaleFactor = grib_arguments_get_name(hand,c,n++);
+ self->scaledValue = grib_arguments_get_name(hand,c,n++);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
@@ -154,11 +155,18 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len)
int ret = 0;
long scaleFactor=0;
long scaledValue=0;
+ grib_handle* hand = grib_handle_of_accessor(a);
- if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaleFactor,&scaleFactor)) != GRIB_SUCCESS)
+ if((ret = grib_get_long_internal(hand, self->scaleFactor,&scaleFactor)) != GRIB_SUCCESS)
return ret;
+ /* ECC-966: If scale factor is missing, print error and treat it as zero (as a fallback) */
+ if (grib_is_missing(hand, self->scaleFactor, &ret) && ret == GRIB_SUCCESS) {
+ grib_context_log(a->context, GRIB_LOG_ERROR,
+ "unpack_double for %s: %s is missing! Setting it to zero", a->name, self->scaleFactor);
+ scaleFactor = 0;
+ }
- if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->scaledValue,&scaledValue)) != GRIB_SUCCESS)
+ if((ret = grib_get_long_internal(hand, self->scaledValue,&scaledValue)) != GRIB_SUCCESS)
return ret;
*val=scaledValue;
@@ -191,4 +199,3 @@ static int is_missing(grib_accessor* a)
return ((scaleFactor == GRIB_MISSING_LONG) | (scaledValue == GRIB_MISSING_LONG));
}
-
