ECC-1631: Segmentation fault: Decode bufrdcExpandedDescriptors as string

This commit is contained in:
Shahram Najm 2023-07-08 21:10:17 +00:00
parent 9838b3b21b
commit 0d14b54d80
2 changed files with 22 additions and 17 deletions

View File

@ -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;
}

View File

@ -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