ECC-1741: Assertion failure: Encoding a large field in GRIB1

This commit is contained in:
Shahram Najm 2024-01-08 17:39:10 +00:00
parent ada0309905
commit 42d45cee1e
8 changed files with 16 additions and 10 deletions

View File

@ -801,7 +801,7 @@ void grib_grow_buffer(const grib_context* c, grib_buffer* b, size_t new_size);
void grib_buffer_set_ulength_bits(const grib_context* c, grib_buffer* b, size_t length_bits);
void grib_buffer_set_ulength(const grib_context* c, grib_buffer* b, size_t length);
void grib_recompute_sections_lengths(grib_section* s);
void grib_buffer_replace(grib_accessor* a, const unsigned char* data, size_t newsize, int update_lengths, int update_paddings);
int grib_buffer_replace(grib_accessor* a, const unsigned char* data, size_t newsize, int update_lengths, int update_paddings);
void grib_update_sections_lengths(grib_handle* h);
/* grib_dumper.cc*/

View File

@ -322,7 +322,8 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth)
if (update) {
plen = length;
lret = grib_pack_long(s->aclength, &plen, &len);
Assert(lret == GRIB_SUCCESS);
if (lret != GRIB_SUCCESS)
return lret;
s->padding = 0;
}
else {

View File

@ -313,7 +313,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
grib_context_log(a->context, GRIB_LOG_DEBUG,
"grib_accessor_data_g1simple_packing : pack_double : packing %s, %d values", a->name, n_vals);
grib_buffer_replace(a, buf, buflen, 1, 1);
ret = grib_buffer_replace(a, buf, buflen, 1, 1);
if (ret != GRIB_SUCCESS) return ret;
grib_context_buffer_free(a->context, buf);

View File

@ -210,6 +210,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
" (actual length=%ld)",
cclass_name, __func__, *val, total_length);
grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try encoding as GRIB2\n");
return GRIB_ENCODING_ERROR;
}
Assert(total_length == *val);
}

View File

@ -149,7 +149,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits, tlen * 8 - *len)) != GRIB_SUCCESS)
return err;
grib_buffer_replace(a, buf, tlen, 1, 1);
err = grib_buffer_replace(a, buf, tlen, 1, 1);
if (err) return err;
grib_context_free(a->context, buf);

View File

@ -195,8 +195,8 @@ static void update_offsets_after(grib_accessor* a, long len)
// update_sections_lengths(s->owner->parent);
// }
void grib_buffer_replace(grib_accessor* a, const unsigned char* data,
size_t newsize, int update_lengths, int update_paddings)
int grib_buffer_replace(grib_accessor* a, const unsigned char* data,
size_t newsize, int update_lengths, int update_paddings)
{
size_t offset = a->offset;
long oldsize = grib_get_next_position_offset(a) - offset;
@ -232,11 +232,13 @@ void grib_buffer_replace(grib_accessor* a, const unsigned char* data,
update_offsets_after(a, increase);
if (update_lengths) {
grib_update_size(a, newsize);
grib_section_adjust_sizes(grib_handle_of_accessor(a)->root, 1, 0);
int err = grib_section_adjust_sizes(grib_handle_of_accessor(a)->root, 1, 0);
if (err) return err;
if (update_paddings)
grib_update_paddings(grib_handle_of_accessor(a)->root);
}
}
return GRIB_SUCCESS;
}
void grib_update_sections_lengths(grib_handle* h)

View File

@ -755,7 +755,7 @@ int grib_set_double_array_internal(grib_handle* h, const char* name, const doubl
}
if (ret != GRIB_SUCCESS)
grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set double array %s (%s)",
grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set double array '%s' (%s)",
name, grib_get_error_message(ret));
/*if (h->context->debug) fprintf(stderr,"ECCODES DEBUG grib_set_double_array_internal key=%s --DONE\n",name);*/
return ret;
@ -928,7 +928,7 @@ int grib_set_long_array_internal(grib_handle* h, const char* name, const long* v
{
int ret = _grib_set_long_array(h, name, val, length, 0);
if (ret != GRIB_SUCCESS)
grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set long array %s (%s)",
grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set long array '%s' (%s)",
name, grib_get_error_message(ret));
return ret;
}

View File

@ -53,7 +53,7 @@ infile=${data_dir}/sample.grib2
set +e
${tools_dir}/grib_set -r -s packingType=grid_png $infile $temp > $tempErr 2>&1
set -e
grep -q "Unable to set double array codedValues" $tempErr
grep -q "Unable to set double array 'codedValues'" $tempErr
# Nearest neighbour
# ----------------------