From patchwork Thu Sep 19 19:37:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 15154 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4BE67447097 for ; Thu, 19 Sep 2019 22:45:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 34CE6689D84; Thu, 19 Sep 2019 22:45:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-2.mx.upcmail.net (vie01a-dmta-pe06-2.mx.upcmail.net [84.116.36.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E641A689997 for ; Thu, 19 Sep 2019 22:45:34 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iB2Ge-0008Cl-1x for ffmpeg-devel@ffmpeg.org; Thu, 19 Sep 2019 21:39:04 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id B2FgiIJO5wlysB2FgiJk5l; Thu, 19 Sep 2019 21:38:04 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=_y3xK_3TYRqA12XLoJIA:9 a=0bXxn9q0MV6snEgNplNhOjQmxlI=:19 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 19 Sep 2019 21:37:40 +0200 Message-Id: <20190919193741.21138-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919193741.21138-1-michael@niedermayer.cc> References: <20190919193741.21138-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfGYCyblElfZOPsY2iIsaiPg+tYWDKw4GJwCAv7IIY1N9MSk3RI/OqUGMxxJBpPdprXK8Zy55+vbquGgmUwIdmuARaiCu1lfh4RyWqWvDJ5LHWPhdo5ig L6W5Y7N+s4FT3Kp2gk6piInxgXkZaz/gyRFCoswp6e5u7UFdeX6vvCia Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/jpeglsdec: Return error codes from ls_decode_line() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index 5308b744df..79f7fc1322 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -222,7 +222,7 @@ static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, /** * 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) { @@ -234,7 +234,7 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, 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); @@ -263,11 +263,11 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, } /* 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]]; @@ -284,7 +284,7 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, if (x >= w) { av_log(NULL, AV_LOG_ERROR, "run overflow\n"); av_assert0(x <= w); - return; + return AVERROR_INVALIDDATA; } /* decode run termination value */ @@ -341,6 +341,8 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, W(dst, x, pred); x += stride; } + + return 0; } int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, @@ -407,13 +409,16 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, 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]; @@ -429,9 +434,12 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, 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) { @@ -439,6 +447,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, skip_bits(&s->gb, 16); /* skip RSTn */ } } + if (ret < 0) + break; last = cur; cur += s->picture_ptr->linesize[0]; }