ECC-1139: CRASH: bufr_ls -p numericValues

This commit is contained in:
Shahram Najm 2020-07-25 17:27:02 +01:00
parent 7874d76141
commit fc5b4f7ec1
3 changed files with 37 additions and 15 deletions

View File

@ -3394,7 +3394,14 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return err;
if (self->compressedData) {
const size_t rlen = l * self->numberOfSubsets;
ii = 0;
if (*len < rlen) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"wrong size (%ld) for %s, it contains %d values ", *len, a->name, rlen);
*len = 0;
return GRIB_ARRAY_TOO_SMALL;
}
for (k = 0; k < numberOfSubsets; k++) {
for (i = 0; i < l; i++) {
val[ii++] = self->numericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0];

View File

@ -16,12 +16,9 @@ cd ${data_dir}/bufr
# Define a common label for all the tmp files
label="bufr_ls_test"
# Create log file
fLog=${label}".log"
rm -f $fLog
touch $fLog
# Define tmp file
fTmp=${label}".tmp.txt"
rm -f $fTmp
@ -34,9 +31,9 @@ for f in ${bufr_files} ; do
${tools_dir}/bufr_ls $f >> $fLog
done
#-------------------------------------------
#-----------------
# Test "-p" switch
#-------------------------------------------
#-----------------
f="aaen_55.bufr"
ref_ls=$f".ls.ref"
res_ls=$f".ls.test"
@ -48,6 +45,17 @@ ${tools_dir}/bufr_ls -p totalLength,bufrHeaderCentre,bufrHeaderSubCentre,masterT
awk NR==3 $fTmp | awk '{split($0,a," "); for (i=1; i<=8; i++) print a[i]}' > $res_ls
diff $ref_ls $res_ls
# ------------------------
# Test printing array key
# ------------------------
set +e
${tools_dir}/bufr_ls -p numericValues $f >$fTmp 2>&1
status=$?
set -e
[ $status -ne 0 ]
cat $fTmp
grep -q "Passed array is too small" $fTmp
rm -f $fLog $res_ls
rm -f $fTmp

View File

@ -1072,6 +1072,9 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
/* ECC-236: Do not use grib_is_missing for BUFR */
if (!grib_is_defined(h, options->print_keys[i].name))
ret = GRIB_NOT_FOUND;
if (ret == GRIB_SUCCESS) {
ret = grib_get_size(h, options->print_keys[i].name, &num_vals);
}
if (ret == GRIB_SUCCESS) {
if (options->print_keys[i].type == GRIB_TYPE_UNDEFINED)
grib_get_native_type(h, options->print_keys[i].name, &(options->print_keys[i].type));
@ -1083,18 +1086,22 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
sprintf(value, "MISSING");
break;
case GRIB_TYPE_DOUBLE:
ret = grib_get_double(h, options->print_keys[i].name, &dvalue);
if (dvalue == GRIB_MISSING_DOUBLE)
sprintf(value, "MISSING");
else
sprintf(value, options->format, dvalue);
if (num_vals > 1) {
ret = GRIB_ARRAY_TOO_SMALL;
} else {
ret = grib_get_double(h, options->print_keys[i].name, &dvalue);
if (dvalue == GRIB_MISSING_DOUBLE) sprintf(value, "MISSING");
else sprintf(value, options->format, dvalue);
}
break;
case GRIB_TYPE_LONG:
ret = grib_get_long(h, options->print_keys[i].name, &lvalue);
if (lvalue == GRIB_MISSING_LONG)
sprintf(value, "MISSING");
else
sprintf(value, "%ld", lvalue);
if (num_vals > 1) {
ret = GRIB_ARRAY_TOO_SMALL;
} else {
ret = grib_get_long(h, options->print_keys[i].name, &lvalue);
if (lvalue == GRIB_MISSING_LONG) sprintf(value, "MISSING");
else sprintf(value, "%ld", lvalue);
}
break;
case GRIB_TYPE_BYTES:
ret = grib_get_string(h, options->print_keys[i].name, value, &len);