Skip to content

Commit b9cf94a

Browse files
committed
ECC-1717: CRASH: grib_get -p numberOfMissing on invalid GRIB
1 parent d47b5b1 commit b9cf94a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/grib_accessor_class_count_missing.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,15 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
200200

201201
if (grib_get_long(h, self->unusedBitsInBitmap, &unusedBitsInBitmap) != GRIB_SUCCESS) {
202202
if (grib_get_long(h, self->numberOfDataPoints, &numberOfDataPoints) != GRIB_SUCCESS) {
203-
grib_context_log(a->context, GRIB_LOG_ERROR, "unable to count missing values");
203+
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to count missing values");
204204
return GRIB_INTERNAL_ERROR;
205205
}
206206
unusedBitsInBitmap = size * 8 - numberOfDataPoints;
207+
if (unusedBitsInBitmap < 0) {
208+
grib_context_log(a->context, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!");
209+
grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size*8, numberOfDataPoints);
210+
return GRIB_DECODING_ERROR;
211+
}
207212
}
208213

209214
p = h->buffer->data + offset;

0 commit comments

Comments
 (0)