GRIB-547: Corrupt gribs. Return error from grib_section_adjust_sizes

This commit is contained in:
Shahram Najm 2014-07-17 18:02:49 +01:00
parent ab084c7f20
commit b0db0f2b24
4 changed files with 22 additions and 9 deletions

View File

@ -166,8 +166,10 @@ static int notify_change(grib_action* act, grib_accessor * notified,
tmp_handle->use_trie=1;
err=grib_create_accessor(tmp_handle->root, act, &loader);
if (err) return err;
grib_section_adjust_sizes(tmp_handle->root,1,0);
err = grib_section_adjust_sizes(tmp_handle->root,1,0);
if (err) return err;
grib_section_post_init(tmp_handle->root);
@ -198,7 +200,8 @@ static int notify_change(grib_action* act, grib_accessor * notified,
h->trie_invalid=1;
h->kid = NULL;
grib_section_adjust_sizes(h->root,1,0);
err = grib_section_adjust_sizes(h->root,1,0);
if (err) return err;
grib_section_post_init(h->root);

View File

@ -213,11 +213,11 @@ void grib_section_post_init(grib_section* s)
grib_section_post_init(a->sub_section);
a = a->next;
}
}
void grib_section_adjust_sizes(grib_section* s,int update,int depth)
int grib_section_adjust_sizes(grib_section* s,int update,int depth)
{
int err = 0;
grib_accessor* a = s ? s->block->first : NULL;
size_t length = update ? 0 : (s?s->padding:0);
size_t offset = (s && s->owner) ? s->owner->offset:0;
@ -226,13 +226,16 @@ void grib_section_adjust_sizes(grib_section* s,int update,int depth)
while(a) {
register long l;
/* grib_section_adjust_sizes(grib_get_sub_section(a),update,depth+1); */
grib_section_adjust_sizes(a->sub_section,update,depth+1);
err = grib_section_adjust_sizes(a->sub_section,update,depth+1);
if (err) return err;
l = a->length;
if(offset != a->offset) {
grib_context_log(a->parent->h->context,GRIB_LOG_DEBUG,"Offset mismatch %s A->offset %ld offset %ld\n",a->name,(long)a->offset, (long)offset);
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"Offset mismatch %s A->offset %ld offset %ld\n",a->name,(long)a->offset, (long)offset);
a->offset = offset;
return GRIB_DECODING_ERROR;
}
length += l;
offset += l;
@ -275,7 +278,7 @@ void grib_section_adjust_sizes(grib_section* s,int update,int depth)
if(s->owner) s->owner->length = length;
s->length = length;
}
return err;
}
int grib_get_block_length(grib_section* s, size_t *l)

View File

@ -263,7 +263,7 @@ grib_section *grib_create_root_section(const grib_context *context, grib_handle
grib_accessor *grib_accessor_factory(grib_section *p, grib_action *creator, const long len, grib_arguments *params);
void grib_push_accessor(grib_accessor *a, grib_block_of_accessors *l);
void grib_section_post_init(grib_section *s);
void grib_section_adjust_sizes(grib_section *s, int update, int depth);
int grib_section_adjust_sizes(grib_section *s, int update, int depth);
int grib_get_block_length(grib_section *s, size_t *l);
grib_accessor *find_paddings(grib_section *s);
void grib_update_paddings(grib_section *s);

View File

@ -197,6 +197,7 @@ static void check_definitions_version(grib_handle* h)
static grib_handle* grib_handle_create ( grib_handle *gl, grib_context* c,void* data, size_t buflen )
{
grib_action* next = NULL;
int err = 0;
if ( gl == NULL )
return NULL;
@ -237,7 +238,13 @@ static grib_handle* grib_handle_create ( grib_handle *gl, grib_context* c,void*
next = next->next;
}
grib_section_adjust_sizes ( gl->root,0,0 );
err = grib_section_adjust_sizes ( gl->root,0,0 );
if (err)
{
grib_handle_delete ( gl );
return NULL;
}
grib_section_post_init ( gl->root );
check_definitions_version(gl);