mirror of https://github.com/ecmwf/eccodes.git
ECC-517: crash/error setting inputExtendedDelayedDescriptorReplicationFactor > 486
This commit is contained in:
parent
f649013ee2
commit
90a86d93d7
|
@ -912,6 +912,7 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
|
|||
double cdval=0,x;
|
||||
int err=0;
|
||||
bufr_descriptor* bd = descriptor==NULL ? self->expanded->v[i] : descriptor ;
|
||||
/* Assert( b->data == data); */
|
||||
|
||||
if (self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255) {
|
||||
/* Operator 203YYY: Change Reference Values: Definition phase */
|
||||
|
@ -983,6 +984,9 @@ static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* sel
|
|||
bufr_descriptor** descriptors=0;
|
||||
err=&ret;
|
||||
descriptors=self->expanded->v;
|
||||
|
||||
/* Assert(buff->data == data); */
|
||||
|
||||
grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: -%ld- \tcode=%6.6ld width=%ld ",
|
||||
i,self->expanded->v[i]->code,self->expanded->v[i]->width);
|
||||
if (self->compressedData) {
|
||||
|
@ -1098,6 +1102,7 @@ static int encode_new_replication(grib_context* c,grib_accessor_bufr_data_array*
|
|||
int err=0;
|
||||
unsigned long repetitions=1;
|
||||
bufr_descriptor** descriptors=self->expanded->v;
|
||||
/* Assert( buff->data==data); */
|
||||
|
||||
switch(descriptors[i]->code) {
|
||||
case 31000:
|
||||
|
@ -1154,6 +1159,7 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
|
|||
int idx,j;
|
||||
int err=0;
|
||||
bufr_descriptor* bd = descriptor==NULL ? self->expanded->v[i] : descriptor ;
|
||||
/* Assert( buff->data == data); */
|
||||
|
||||
grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data encoding: -%ld- \tcode=%6.6ld width=%ld pos=%ld ulength=%ld ulength_bits=%ld",
|
||||
i,bd->code,bd->width,(long)*pos,buff->ulength,buff->ulength_bits);
|
||||
|
@ -1196,6 +1202,7 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in
|
|||
static int encode_replication(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex,
|
||||
grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions)
|
||||
{
|
||||
/* Assert( buff->data == data); */
|
||||
if (self->compressedData) {
|
||||
Assert(grib_darray_used_size(self->numericValues->v[elementIndex])==1);
|
||||
*numberOfRepetitions=self->numericValues->v[elementIndex]->v[0];
|
||||
|
@ -2323,7 +2330,7 @@ static int process_elements(grib_accessor* a,int flag,long onlySubset,long start
|
|||
default :
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
data=(unsigned char*)buffer->data;
|
||||
data = buffer->data;
|
||||
|
||||
err=get_descriptors(a);
|
||||
if (err) return err;
|
||||
|
@ -2404,6 +2411,8 @@ static int process_elements(grib_accessor* a,int flag,long onlySubset,long start
|
|||
n[inr]=numberOfElementsToRepeat[inr];
|
||||
i++;
|
||||
|
||||
/* ECC-517 */
|
||||
data = buffer->data;
|
||||
err=codec_replication(c,self,iss,buffer,data,&pos,i,elementIndex,dval,&(numberOfRepetitions[inr]));
|
||||
if (err) return err;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ list( APPEND test_bins
|
|||
optimize_scaling
|
||||
optimize_scaling_sh
|
||||
ecc-386
|
||||
ecc-517
|
||||
bufr_get_element
|
||||
sh_ieee64
|
||||
ieee
|
||||
|
@ -50,6 +51,7 @@ list( APPEND tests_no_data_reqd
|
|||
uerra
|
||||
grib_2nd_order_numValues
|
||||
julian
|
||||
ecc-517
|
||||
)
|
||||
# These tests do require data downloads
|
||||
list( APPEND tests_data_reqd
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
#include "eccodes.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
size_t size=0;
|
||||
const void* buffer = NULL;
|
||||
FILE* fout = NULL;
|
||||
codes_handle* h = NULL;
|
||||
long* ivalues = NULL;
|
||||
char** svalues = NULL;
|
||||
double* rvalues = NULL;
|
||||
const char* sampleName = "BUFR3_local";
|
||||
char* outfilename = NULL;
|
||||
|
||||
assert(argc == 2);
|
||||
outfilename = argv[1];
|
||||
|
||||
h = codes_bufr_handle_new_from_samples(NULL, sampleName);
|
||||
assert(h);
|
||||
|
||||
ivalues = (long*)malloc(1*sizeof(long));
|
||||
if (!ivalues) { fprintf(stderr, "Failed to allocate memory (ivalues).\n"); return 1; }
|
||||
size = 1;ivalues[0]=1;
|
||||
CODES_CHECK(codes_set_long_array(h, "inputDelayedDescriptorReplicationFactor", ivalues, size), 0);
|
||||
|
||||
ivalues = (long*)malloc(1*sizeof(long));
|
||||
size = 1;ivalues[0]=486;
|
||||
CODES_CHECK(codes_set_long_array(h, "inputExtendedDelayedDescriptorReplicationFactor", ivalues, size), 0);
|
||||
|
||||
CODES_CHECK(codes_set_long(h, "edition", 3), 0);
|
||||
CODES_CHECK(codes_set_long(h, "masterTableNumber", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "bufrHeaderSubCentre", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", 98), 0);
|
||||
CODES_CHECK(codes_set_long(h, "updateSequenceNumber", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "dataCategory", 2), 0);
|
||||
CODES_CHECK(codes_set_long(h, "dataSubCategory", 109), 0);
|
||||
CODES_CHECK(codes_set_long(h, "masterTablesVersionNumber", 13), 0);
|
||||
CODES_CHECK(codes_set_long(h, "localTablesVersionNumber", 1), 0);
|
||||
CODES_CHECK(codes_set_long(h, "typicalYearOfCentury", 17), 0);
|
||||
CODES_CHECK(codes_set_long(h, "typicalMonth", 8), 0);
|
||||
CODES_CHECK(codes_set_long(h, "typicalDay", 6), 0);
|
||||
CODES_CHECK(codes_set_long(h, "typicalHour", 11), 0);
|
||||
CODES_CHECK(codes_set_long(h, "typicalMinute", 15), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rdbType", 5), 0);
|
||||
CODES_CHECK(codes_set_long(h, "oldSubtype", 109), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rdbtimeDay", 7), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rdbtimeHour", 11), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rdbtimeMinute", 13), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rdbtimeSecond", 46), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rectimeDay", 7), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rectimeHour", 11), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rectimeMinute", 13), 0);
|
||||
CODES_CHECK(codes_set_long(h, "rectimeSecond", 46), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction1", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction1Part", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction2", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction2Part", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction3", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction3Part", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction4", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "correction4Part", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "qualityControl", 70), 0);
|
||||
CODES_CHECK(codes_set_long(h, "newSubtype", 0), 0);
|
||||
CODES_CHECK(codes_set_long(h, "numberOfSubsets", 1), 0);
|
||||
CODES_CHECK(codes_set_double(h, "localLatitude", 5.450296999999999770e+01), 0);
|
||||
CODES_CHECK(codes_set_double(h, "localLongitude", -6.343119999999999870e+00), 0);
|
||||
CODES_CHECK(codes_set_long(h, "observedData", 1), 0);
|
||||
CODES_CHECK(codes_set_long(h, "compressedData", 0), 0);
|
||||
free(ivalues); ivalues = NULL;
|
||||
|
||||
ivalues = (long*)malloc(9*sizeof(long));
|
||||
if (!ivalues) { fprintf(stderr, "Failed to allocate memory (ivalues).\n"); return 1; }
|
||||
size = 4;
|
||||
ivalues[0]= 309052;
|
||||
ivalues[1]= 5001;
|
||||
ivalues[2]= 6001;
|
||||
ivalues[3]= 7001;
|
||||
CODES_CHECK(codes_set_long_array(h, "unexpandedDescriptors", ivalues, size), 0);
|
||||
|
||||
/* Encode the keys back in the data section */
|
||||
CODES_CHECK(codes_set_long(h, "pack", 1), 0);
|
||||
|
||||
fout = fopen(outfilename, "w");
|
||||
if (!fout) {
|
||||
fprintf(stderr, "Failed to open (create) output file.\n");
|
||||
return 1;
|
||||
}
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
if (fwrite(buffer,1,size,fout) != size) {
|
||||
fprintf(stderr, "Failed to write data.\n");
|
||||
return 1;
|
||||
}
|
||||
if (fclose(fout)!=0) {
|
||||
fprintf(stderr, "Failed to close file handle.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
codes_handle_delete(h);
|
||||
free(ivalues); ivalues = NULL;
|
||||
free(rvalues); rvalues = NULL;
|
||||
free(svalues); svalues = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
# Copyright 2005-2017 ECMWF.
|
||||
#
|
||||
# This software is licensed under the terms of the Apache Licence Version 2.0
|
||||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
#
|
||||
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
#
|
||||
|
||||
. ./include.sh
|
||||
|
||||
# The program produces a BUFR file as output
|
||||
OUTPUT=temp.ecc-517.bufr
|
||||
${test_dir}/ecc-517 $OUTPUT
|
||||
|
||||
rm $OUTPUT
|
Loading…
Reference in New Issue