/**
* Decode one line of image
*/
-static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s,
+static inline int ls_decode_line(JLSState *state, MJpegDecodeContext *s,
void *last, void *dst, int last2, int w,
int stride, int comp, int bits)
{
int err, pred;
if (get_bits_left(&s->gb) <= 0)
- return;
+ return AVERROR_INVALIDDATA;
/* compute gradients */
Ra = x ? R(dst, x - stride) : R(last, x);
}
/* if EOL reached, we stop decoding */
if (r != 1 << ff_log2_run[state->run_index[comp]])
- return;
+ return 0;
if (state->run_index[comp] < 31)
state->run_index[comp]++;
if (x + stride > w)
- return;
+ return 0;
}
/* decode aborted run */
r = ff_log2_run[state->run_index[comp]];
if (x >= w) {
av_log(NULL, AV_LOG_ERROR, "run overflow\n");
av_assert0(x <= w);
- return;
+ return AVERROR_INVALIDDATA;
}
/* decode run termination value */
W(dst, x, pred);
x += stride;
}
+
+ return 0;
}
int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near,
uint8_t *zero, *last, *cur;
JLSState *state;
int off = 0, stride = 1, width, shift, ret = 0;
+ int decoded_height = 0;
zero = av_mallocz(s->picture_ptr->linesize[0]);
if (!zero)
width = s->width * stride;
cur += off;
for (i = 0; i < s->height; i++) {
+ int ret;
if (s->bits <= 8) {
- ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
+ ret = ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
t = last[0];
} else {
- ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
+ ret = ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
t = *((uint16_t *)last);
}
+ if (ret < 0)
+ break;
last = cur;
cur += s->picture_ptr->linesize[0];
skip_bits(&s->gb, 16); /* skip RSTn */
}
}
+ decoded_height = i;
} else if (ilv == 1) { /* line interleaving */
int j;
int Rc[3] = { 0, 0, 0 };
memset(cur, 0, s->picture_ptr->linesize[0]);
width = s->width * stride;
for (i = 0; i < s->height; i++) {
+ int ret;
for (j = 0; j < stride; j++) {
- ls_decode_line(state, s, last + j, cur + j,
+ ret = ls_decode_line(state, s, last + j, cur + j,
Rc[j], width, stride, j, 8);
+ if (ret < 0)
+ break;
Rc[j] = last[j];
if (s->restart_interval && !--s->restart_count) {
skip_bits(&s->gb, 16); /* skip RSTn */
}
}
+ if (ret < 0)
+ break;
last = cur;
cur += s->picture_ptr->linesize[0];
}
+ decoded_height = i;
} else if (ilv == 2) { /* sample interleaving */
avpriv_report_missing_feature(s->avctx, "Sample interleaved images");
ret = AVERROR_PATCHWELCOME;
if (s->bits <= 8) {
uint8_t *src = s->picture_ptr->data[0];
- for (i = 0; i < s->height; i++) {
+ for (i = 0; i < decoded_height; i++) {
for (x = off; x < w; x += stride)
src[x] <<= shift;
src += s->picture_ptr->linesize[0];
} else {
uint16_t *src = (uint16_t *)s->picture_ptr->data[0];
- for (i = 0; i < s->height; i++) {
+ for (i = 0; i < decoded_height; i++) {
for (x = 0; x < w; x++)
src[x] <<= shift;
src += s->picture_ptr->linesize[0] / 2;