mirror of https://github.com/ecmwf/eccodes.git
GRIB-364: Memory fault when packing GRIB2 files with 'log preprocessing'
This commit is contained in:
commit
6dc79a4a78
|
@ -216,7 +216,17 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||||
for (i = 0; i < n_vals; i++)
|
for (i = 0; i < n_vals; i++)
|
||||||
val[i] += units_bias;
|
val[i] += units_bias;
|
||||||
|
|
||||||
ret = super->pack_double(a, val, len);
|
if (super != grib_accessor_class_data_g2simple_packing) {
|
||||||
|
/* Normal case: parent not same as me! */
|
||||||
|
ret = super->pack_double(a, val, len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* GRIB-364: simple packing with logarithm pre-processing */
|
||||||
|
grib_accessor_class* super2 = NULL;
|
||||||
|
Assert(super->super);
|
||||||
|
super2 = *(super->super);
|
||||||
|
ret = super2->pack_double(a, val, len);
|
||||||
|
}
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case GRIB_CONSTANT_FIELD:
|
case GRIB_CONSTANT_FIELD:
|
||||||
grib_buffer_replace(a, NULL, 0, 1, 1);
|
grib_buffer_replace(a, NULL, 0, 1, 1);
|
||||||
|
|
|
@ -183,6 +183,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
{
|
{
|
||||||
grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a;
|
grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a;
|
||||||
grib_accessor_class* super = *(a->cclass->super);
|
grib_accessor_class* super = *(a->cclass->super);
|
||||||
|
grib_accessor_class* super2 = NULL;
|
||||||
|
|
||||||
size_t n_vals = 0;
|
size_t n_vals = 0;
|
||||||
long nn = 0;
|
long nn = 0;
|
||||||
|
@ -213,7 +214,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = super->unpack_double(a, val, &n_vals);
|
Assert(super->super);
|
||||||
|
super2 = *(super->super);
|
||||||
|
err = super2->unpack_double(a, val, &n_vals); /* GRIB-364 */
|
||||||
if (err != GRIB_SUCCESS)
|
if (err != GRIB_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -266,6 +269,7 @@ static int pre_processing_func(double* values, long length, long pre_processing,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
double min = values[0];
|
double min = values[0];
|
||||||
double next_min = values[0];
|
double next_min = values[0];
|
||||||
|
Assert(length > 0);
|
||||||
|
|
||||||
switch (pre_processing) {
|
switch (pre_processing) {
|
||||||
/* NONE */
|
/* NONE */
|
||||||
|
@ -286,15 +290,21 @@ static int pre_processing_func(double* values, long length, long pre_processing,
|
||||||
}
|
}
|
||||||
if (min > 0) {
|
if (min > 0) {
|
||||||
*pre_processing_parameter = 0;
|
*pre_processing_parameter = 0;
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++) {
|
||||||
|
DebugAssert(values[i] > 0);
|
||||||
values[i] = log(values[i]);
|
values[i] = log(values[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
double ppp = 0;
|
||||||
*pre_processing_parameter = next_min - 2 * min;
|
*pre_processing_parameter = next_min - 2 * min;
|
||||||
if (next_min == min)
|
if (next_min == min)
|
||||||
return ret;
|
return ret;
|
||||||
for (i = 0; i < length; i++)
|
ppp = *pre_processing_parameter;
|
||||||
values[i] = log(values[i] + *pre_processing_parameter);
|
for (i = 0; i < length; i++) {
|
||||||
|
DebugAssert((values[i] + ppp) > 0);
|
||||||
|
values[i] = log(values[i] + ppp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -18,8 +18,8 @@ packing1="
|
||||||
packing2="
|
packing2="
|
||||||
grid_ieee
|
grid_ieee
|
||||||
grid_simple
|
grid_simple
|
||||||
grid_simple_matrix"
|
grid_simple_matrix
|
||||||
#TODO: grid_simple_log_preprocessing
|
grid_simple_log_preprocessing"
|
||||||
|
|
||||||
if [ $HAVE_JPEG -eq 1 ]; then
|
if [ $HAVE_JPEG -eq 1 ]; then
|
||||||
packing2="grid_jpeg "$packing2
|
packing2="grid_jpeg "$packing2
|
||||||
|
|
Loading…
Reference in New Issue