ECC-1395: BUFR: Encoding should fail if attempting to encode message with an undefined element descriptor

This commit is contained in:
Shahram Najm 2022-06-01 16:38:24 +01:00
parent 2c11c7ad9c
commit b8ae44fccf
2 changed files with 18 additions and 8 deletions

View File

@ -766,7 +766,11 @@ static int descriptor_get_min_max(bufr_descriptor* bd, long width, long referenc
double* minAllowed, double* maxAllowed)
{
/* Maximum value is allowed to be the largest number (all bits 1) which means it's MISSING */
size_t max1 = (1ULL << width) - 1; /* Highest value for number with 'width' bits */
const size_t max1 = (1ULL << width) - 1; /* Highest value for number with 'width' bits */
if (width <= 0)
return GRIB_MISSING_BUFR_ENTRY; /* ECC-1395 */
DebugAssert(width > 0 && width < 64);
*maxAllowed = (max1 + reference) * factor;
@ -804,7 +808,8 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu
inverseFactor = grib_power(bd->scale, 10);
modifiedWidth = bd->width;
descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed);
err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed);
if (err) return err;
nvals = grib_iarray_used_size(self->iss_list);
if (nvals <= 0)
@ -1006,7 +1011,8 @@ static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bu
modifiedFactor = bd->factor;
modifiedWidth = bd->width;
descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed);
err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed);
if (err) return err;
grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + modifiedWidth);
if (value == GRIB_MISSING_DOUBLE) {

View File

@ -10,15 +10,16 @@
. ./include.ctest.sh
REDIRECT=/dev/null
label="bufr_ecc-1395_test"
temp=temp.$label
tempBufr=temp.$label.bufr
tempFilt=temp.$label.filt
tempOut=temp.$label.out
sample_bufr4=$ECCODES_SAMPLES_PATH/BUFR4.tmpl
rm -f $tempBufr
# Pick a descriptor that does not exist in version 19
cat > $tempFilt <<EOF
set masterTablesVersionNumber = 19;
@ -27,11 +28,14 @@ cat > $tempFilt <<EOF
EOF
set +e
${tools_dir}/bufr_filter -o $tempBufr $tempFilt $sample_bufr4 # > $tempOut
${tools_dir}/bufr_filter -o $tempBufr $tempFilt $sample_bufr4 > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
# TODO check status
[ ! -f "$tempBufr" ]
grep -q "unable to get descriptor 025195" $tempOut
rm -f $tempFilt $tempBufr $tempOut
rm -f $tempFilt $tempOut