{
uint8_t byte;
- if (s->buf_end - s->buf < 5)
+ if (bytestream2_get_bytes_left(&s->g) < 5)
return AVERROR(EINVAL);
- c->nreslevels = bytestream2_get_byteu(&s->g) + 1; // num of resolution levels - 1
+ /* nreslevels = number of resolution levels
+ = number of decomposition level +1 */
- c->nreslevels = bytestream_get_byte(&s->buf) + 1;
-
- if (c->nreslevels > JPEG2000_MAX_RESLEVELS)
++ c->nreslevels = bytestream2_get_byteu(&s->g) + 1;
+ if (c->nreslevels >= JPEG2000_MAX_RESLEVELS) {
+ av_log(s->avctx, AV_LOG_ERROR, "nreslevels %d is invalid\n", c->nreslevels);
return AVERROR_INVALIDDATA;
+ }
/* compute number of resolution levels to decode */
if (c->nreslevels < s->reduction_factor)