From 0d14b54d8008c196b9045321c72121adbc6e98c7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 8 Jul 2023 21:10:17 +0000 Subject: [PATCH] ECC-1631: Segmentation fault: Decode bufrdcExpandedDescriptors as string --- ...essor_class_bufrdc_expanded_descriptors.cc | 34 +++++++++---------- tests/bufrdc_desc_ref.sh | 5 +++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/grib_accessor_class_bufrdc_expanded_descriptors.cc index 496666651..2bb5d648f 100644 --- a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc +++ b/src/grib_accessor_class_bufrdc_expanded_descriptors.cc @@ -142,15 +142,14 @@ static grib_accessor* get_accessor(grib_accessor* a) static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor* descriptors = 0; - size_t rlen = 0, l; - long lenall = 0; - size_t i; - long* v = 0; + size_t rlen = 0, l; + long lenall = 0; + size_t i = 0; + long* v = 0; grib_context* c = a->context; descriptors = get_accessor(a); - if (!descriptors) - return GRIB_NOT_FOUND; + if (!descriptors) return GRIB_NOT_FOUND; grib_value_count(a, &lenall); v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall); @@ -171,29 +170,30 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) { grib_accessor* descriptors = 0; - grib_context* c = a->context; - long l = 0; - size_t size, i; + size_t l = 0; + long lenall = 0; + size_t i = 0; + long* v = 0; char buf[25] = {0,}; - long* v = 0; + grib_context* c = a->context; descriptors = get_accessor(a); - if (!descriptors) - return GRIB_NOT_FOUND; + if (!descriptors) return GRIB_NOT_FOUND; - value_count(descriptors, &l); + grib_value_count(a, &lenall); + l = lenall; if (l > *len) return GRIB_ARRAY_TOO_SMALL; - v = (long*)grib_context_malloc_clear(c, sizeof(long) * l); - size = l; - unpack_long(a, v, &size); + v = (long*)grib_context_malloc_clear(c, sizeof(long) * l); + grib_unpack_long(descriptors, v, &l); - for (i = 0; i < size; i++) { + for (i = 0; i < l; i++) { snprintf(buf, sizeof(buf), "%06ld", v[i]); buffer[i] = grib_context_strdup(c, buf); } *len = l; + grib_context_free(c,v); return GRIB_SUCCESS; } diff --git a/tests/bufrdc_desc_ref.sh b/tests/bufrdc_desc_ref.sh index 07925d497..f6aa1e55b 100755 --- a/tests/bufrdc_desc_ref.sh +++ b/tests/bufrdc_desc_ref.sh @@ -35,4 +35,9 @@ do rm -f $res_desc $diff_desc done +# ECC-1631: Segmentation fault: Decode bufrdcExpandedDescriptors as string +echo 'print "[bufrdcExpandedDescriptors:s]";' | ${tools_dir}/codes_bufr_filter - $ECCODES_SAMPLES_PATH/BUFR4.tmpl + + +# Clean up rm -f bufrdc_desc_ref.filter