From patchwork Fri Apr 10 19:02:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18816 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 9CE9044B994 for ; Fri, 10 Apr 2020 22:03:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86B0B68B361; Fri, 10 Apr 2020 22:03:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8584E68B06A for ; Fri, 10 Apr 2020 22:03:04 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:03:03 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:17 -0600 Message-ID: <20200410190223.134413-2-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 1/7] lavc/dvbsub: fix potential encode buffer overflow 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" encode buffer size was ignored --- libavcodec/dvbsub.c | 97 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/libavcodec/dvbsub.c b/libavcodec/dvbsub.c index a8d43d81d6..a0be0b1056 100644 --- a/libavcodec/dvbsub.c +++ b/libavcodec/dvbsub.c @@ -37,11 +37,11 @@ typedef struct DVBSubtitleContext { }\ } -static void dvb_encode_rle2(uint8_t **pq, - const uint8_t *bitmap, int linesize, - int w, int h) +static int dvb_encode_rle2(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { - uint8_t *q; + uint8_t *q, *line_begin; unsigned int bitbuf; int bitcnt; int x, y, len, x1, v, color; @@ -49,6 +49,10 @@ static void dvb_encode_rle2(uint8_t **pq, q = *pq; for(y = 0; y < h; y++) { + // Worst case line is 3 bits per value + 4 bytes overhead + if (buf_size * 8 < w * 3 + 32) + return AVERROR_BUFFER_TOO_SMALL; + line_begin = q; *q++ = 0x10; bitbuf = 0; bitcnt = 6; @@ -109,8 +113,11 @@ static void dvb_encode_rle2(uint8_t **pq, } *q++ = 0xf0; bitmap += linesize; + buf_size -= q - line_begin; } + len = q - *pq; *pq = q; + return len; } #define PUTBITS4(val)\ @@ -125,11 +132,11 @@ static void dvb_encode_rle2(uint8_t **pq, } /* some DVB decoders only implement 4 bits/pixel */ -static void dvb_encode_rle4(uint8_t **pq, - const uint8_t *bitmap, int linesize, - int w, int h) +static int dvb_encode_rle4(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { - uint8_t *q; + uint8_t *q, *line_begin; unsigned int bitbuf; int bitcnt; int x, y, len, x1, v, color; @@ -137,6 +144,10 @@ static void dvb_encode_rle4(uint8_t **pq, q = *pq; for(y = 0; y < h; y++) { + // Worst case line is 6 bits per value, + 4 bytes overhead + if (buf_size * 8 < w * 6 + 32) + return AVERROR_BUFFER_TOO_SMALL; + line_begin = q; *q++ = 0x11; bitbuf = 0; bitcnt = 4; @@ -189,20 +200,27 @@ static void dvb_encode_rle4(uint8_t **pq, } *q++ = 0xf0; bitmap += linesize; + buf_size -= q - line_begin; } + len = q - *pq; *pq = q; + return len; } -static void dvb_encode_rle8(uint8_t **pq, - const uint8_t *bitmap, int linesize, - int w, int h) +static int dvb_encode_rle8(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h) { - uint8_t *q; + uint8_t *q, *line_begin; int x, y, len, x1, color; q = *pq; for (y = 0; y < h; y++) { + // Worst case line is 12 bits per value, + 3 bytes overhead + if (buf_size * 8 < w * 12 + 24) + return AVERROR_BUFFER_TOO_SMALL; + line_begin = q; *q++ = 0x12; x = 0; @@ -243,12 +261,16 @@ static void dvb_encode_rle8(uint8_t **pq, *q++ = 0x00; *q++ = 0xf0; bitmap += linesize; + buf_size -= q - line_begin; } + len = q - *pq; *pq = q; + return len; } static int encode_dvb_subtitles(AVCodecContext *avctx, - uint8_t *outbuf, const AVSubtitle *h) + uint8_t *outbuf, int buf_size, + const AVSubtitle *h) { DVBSubtitleContext *s = avctx->priv_data; uint8_t *q, *pseg_len; @@ -263,6 +285,8 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, return -1; if (avctx->width > 0 && avctx->height > 0) { + if (buf_size < 11) + return AVERROR_BUFFER_TOO_SMALL; /* display definition segment */ *q++ = 0x0f; /* sync_byte */ *q++ = 0x14; /* segment_type */ @@ -273,10 +297,13 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, bytestream_put_be16(&q, avctx->width - 1); /* display width */ bytestream_put_be16(&q, avctx->height - 1); /* display height */ bytestream_put_be16(&pseg_len, q - pseg_len - 2); + buf_size -= 11; } /* page composition segment */ + if (buf_size < 8 + h->num_rects * 6) + return AVERROR_BUFFER_TOO_SMALL; *q++ = 0x0f; /* sync_byte */ *q++ = 0x10; /* segment_type */ bytestream_put_be16(&q, page_id); @@ -295,9 +322,12 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, } bytestream_put_be16(&pseg_len, q - pseg_len - 2); + buf_size -= 8 + h->num_rects * 6; if (h->num_rects) { for (clut_id = 0; clut_id < h->num_rects; clut_id++) { + if (buf_size < 6 + h->rects[clut_id]->nb_colors * 6) + return AVERROR_BUFFER_TOO_SMALL; /* CLUT segment */ @@ -343,9 +373,12 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, } bytestream_put_be16(&pseg_len, q - pseg_len - 2); + buf_size -= 6 + h->rects[clut_id]->nb_colors * 6; } } + if (buf_size < h->num_rects * 22) + return AVERROR_BUFFER_TOO_SMALL; for (region_id = 0; region_id < h->num_rects; region_id++) { /* region composition segment */ @@ -385,13 +418,17 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, bytestream_put_be16(&pseg_len, q - pseg_len - 2); } + buf_size -= h->num_rects * 22; if (h->num_rects) { for (object_id = 0; object_id < h->num_rects; object_id++) { - void (*dvb_encode_rle)(uint8_t **pq, - const uint8_t *bitmap, int linesize, - int w, int h); + int (*dvb_encode_rle)(uint8_t **pq, int buf_size, + const uint8_t *bitmap, int linesize, + int w, int h); + + if (buf_size < 13) + return AVERROR_BUFFER_TOO_SMALL; /* bpp_index maths */ if (h->rects[object_id]->nb_colors <= 4) { @@ -420,19 +457,32 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, non_modifying_color_flag */ { uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr; + int ret; ptop_field_len = q; q += 2; pbottom_field_len = q; q += 2; + buf_size -= 13; top_ptr = q; - dvb_encode_rle(&q, h->rects[object_id]->data[0], h->rects[object_id]->w * 2, - h->rects[object_id]->w, h->rects[object_id]->h >> 1); + ret = dvb_encode_rle(&q, buf_size, + h->rects[object_id]->data[0], + h->rects[object_id]->w * 2, + h->rects[object_id]->w, + h->rects[object_id]->h >> 1); + if (ret < 0) + return ret; + buf_size -= ret; bottom_ptr = q; - dvb_encode_rle(&q, h->rects[object_id]->data[0] + h->rects[object_id]->w, - h->rects[object_id]->w * 2, h->rects[object_id]->w, - h->rects[object_id]->h >> 1); + ret = dvb_encode_rle(&q, buf_size, + h->rects[object_id]->data[0] + h->rects[object_id]->w, + h->rects[object_id]->w * 2, + h->rects[object_id]->w, + h->rects[object_id]->h >> 1); + if (ret < 0) + return ret; + buf_size -= ret; bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr); bytestream_put_be16(&pbottom_field_len, q - bottom_ptr); @@ -444,6 +494,8 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* end of display set segment */ + if (buf_size < 6) + return AVERROR_BUFFER_TOO_SMALL; *q++ = 0x0f; /* sync_byte */ *q++ = 0x80; /* segment_type */ bytestream_put_be16(&q, page_id); @@ -451,6 +503,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, q += 2; /* segment length */ bytestream_put_be16(&pseg_len, q - pseg_len - 2); + buf_size -= 6; s->object_version = (s->object_version + 1) & 0xf; return q - outbuf; @@ -462,7 +515,7 @@ static int dvbsub_encode(AVCodecContext *avctx, { int ret; - ret = encode_dvb_subtitles(avctx, buf, sub); + ret = encode_dvb_subtitles(avctx, buf, buf_size, sub); return ret; } From patchwork Fri Apr 10 19:02:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18817 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 9E8A9449F93 for ; Fri, 10 Apr 2020 22:03:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8788B68B332; Fri, 10 Apr 2020 22:03:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABF6968B302 for ; Fri, 10 Apr 2020 22:03:46 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:03:45 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:18 -0600 Message-ID: <20200410190223.134413-3-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 2/7] lavc/dvbsub: return meaningful error codes 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" --- libavcodec/dvbsub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/dvbsub.c b/libavcodec/dvbsub.c index a0be0b1056..5c081f2b71 100644 --- a/libavcodec/dvbsub.c +++ b/libavcodec/dvbsub.c @@ -282,7 +282,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, page_id = 1; if (h->num_rects && !h->rects) - return -1; + return AVERROR(EINVAL); if (avctx->width > 0 && avctx->height > 0) { if (buf_size < 11) @@ -341,7 +341,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ bpp_index = 2; } else { - return -1; + return AVERROR(EINVAL); } @@ -393,7 +393,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ bpp_index = 2; } else { - return -1; + return AVERROR(EINVAL); } *q++ = 0x0f; /* sync_byte */ @@ -441,7 +441,7 @@ static int encode_dvb_subtitles(AVCodecContext *avctx, /* 8 bpp, standard encoding */ dvb_encode_rle = dvb_encode_rle8; } else { - return -1; + return AVERROR(EINVAL); } /* Object Data segment */ From patchwork Fri Apr 10 19:02:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18818 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 A2FA7449F93 for ; Fri, 10 Apr 2020 22:03:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 898D068B547; Fri, 10 Apr 2020 22:03:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 417C668B4DE for ; Fri, 10 Apr 2020 22:03:54 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:03:52 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:19 -0600 Message-ID: <20200410190223.134413-4-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 3/7] lavc/assenc: return more meaningful error code 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" When the buffer is too small, return AVERROR_BUFFER_TOO_SMALL --- libavcodec/assenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c index e54c1d8ec3..a6e1d5d8b9 100644 --- a/libavcodec/assenc.c +++ b/libavcodec/assenc.c @@ -93,7 +93,7 @@ static int ass_encode_frame(AVCodecContext *avctx, if (len > bufsize-total_len-1) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); - return AVERROR(EINVAL); + return AVERROR_BUFFER_TOO_SMALL; } total_len += len; From patchwork Fri Apr 10 19:02:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18819 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 D2D9844A253 for ; Fri, 10 Apr 2020 22:04:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA07D68B554; Fri, 10 Apr 2020 22:04:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1661B68AF42 for ; Fri, 10 Apr 2020 22:04:28 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:04:26 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:20 -0600 Message-ID: <20200410190223.134413-5-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 4/7] lavc/movtextenc: return more meaningful error codes 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" --- libavcodec/movtextenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index d8dbc546aa..b2368b641b 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -693,7 +693,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); - return AVERROR(ENOSYS); + return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -736,7 +736,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, if (s->buffer.len > bufsize - 3) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); - length = AVERROR(EINVAL); + length = AVERROR_BUFFER_TOO_SMALL; goto exit; } From patchwork Fri Apr 10 19:02:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18820 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 DD87344A253 for ; Fri, 10 Apr 2020 22:04:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C868268B56C; Fri, 10 Apr 2020 22:04:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE0E668B2B1 for ; Fri, 10 Apr 2020 22:04:35 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:04:34 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:21 -0600 Message-ID: <20200410190223.134413-6-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 5/7] lavc/srtenc: return more meaninful error codes 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" --- libavcodec/srtenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c index 34f0f0d5e6..655b65679e 100644 --- a/libavcodec/srtenc.c +++ b/libavcodec/srtenc.c @@ -241,7 +241,7 @@ static int encode_frame(AVCodecContext *avctx, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); - return AVERROR(ENOSYS); + return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -276,7 +276,7 @@ static int encode_frame(AVCodecContext *avctx, if (s->buffer.len > bufsize) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); - return -1; + return AVERROR_BUFFER_TOO_SMALL; } memcpy(buf, s->buffer.str, s->buffer.len); From patchwork Fri Apr 10 19:02:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18821 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 DE9C844A36F for ; Fri, 10 Apr 2020 22:05:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5BF468B5E6; Fri, 10 Apr 2020 22:05:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC70268B58E for ; Fri, 10 Apr 2020 22:05:16 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:05:15 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:22 -0600 Message-ID: <20200410190223.134413-7-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 6/7] lavc/webvttenc: return more meaningful error codes 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" --- libavcodec/webvttenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c index c84bbf4b4e..febf6ee370 100644 --- a/libavcodec/webvttenc.c +++ b/libavcodec/webvttenc.c @@ -168,7 +168,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx, if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); - return AVERROR(ENOSYS); + return AVERROR(EINVAL); } #if FF_API_ASS_TIMING @@ -200,7 +200,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx, if (s->buffer.len > bufsize) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); - return -1; + return AVERROR_BUFFER_TOO_SMALL; } memcpy(buf, s->buffer.str, s->buffer.len); From patchwork Fri Apr 10 19:02:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18822 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 F39A944A36F for ; Fri, 10 Apr 2020 22:05:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC38968B5F1; Fri, 10 Apr 2020 22:05:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9283968B5C9 for ; Fri, 10 Apr 2020 22:05:24 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Fri, 10 Apr 2020 12:05:23 -0700 From: John Stebbins To: Date: Fri, 10 Apr 2020 13:02:23 -0600 Message-ID: <20200410190223.134413-8-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200410190223.134413-1-jstebbins@jetheaddev.com> References: <20200410190223.134413-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 7/7] lavc/xsubenc: return meaningfull error codes 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" --- libavcodec/xsubenc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c index b3da909679..4d58e0f3b5 100644 --- a/libavcodec/xsubenc.c +++ b/libavcodec/xsubenc.c @@ -63,7 +63,7 @@ static int xsub_encode_rle(PutBitContext *pb, const uint8_t *bitmap, while (x0 < w) { // Make sure we have enough room for at least one run and padding if (pb->size_in_bits - put_bits_count(pb) < 7*8) - return -1; + return AVERROR_BUFFER_TOO_SMALL; x1 = x0; color = bitmap[x1++] & 3; @@ -124,7 +124,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, if (bufsize < 27 + 7*2 + 4*3) { av_log(avctx, AV_LOG_ERROR, "Buffer too small for XSUB header.\n"); - return -1; + return AVERROR_BUFFER_TOO_SMALL; } // TODO: support multiple rects @@ -147,7 +147,7 @@ FF_ENABLE_DEPRECATION_WARNINGS // TODO: render text-based subtitles into bitmaps if (!h->rects[0]->data[0] || !h->rects[0]->data[1]) { av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n"); - return -1; + return AVERROR(EINVAL); } // TODO: color reduction, similar to dvdsub encoder @@ -160,7 +160,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) { av_log(avctx, AV_LOG_WARNING, "Time code >= 100 hours.\n"); - return -1; + return AVERROR(EINVAL); } snprintf(buf, 28, @@ -195,13 +195,13 @@ FF_ENABLE_DEPRECATION_WARNINGS if (xsub_encode_rle(&pb, h->rects[0]->data[0], h->rects[0]->linesize[0] * 2, h->rects[0]->w, (h->rects[0]->h + 1) >> 1)) - return -1; + return AVERROR_BUFFER_TOO_SMALL; bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field if (xsub_encode_rle(&pb, h->rects[0]->data[0] + h->rects[0]->linesize[0], h->rects[0]->linesize[0] * 2, h->rects[0]->w, h->rects[0]->h >> 1)) - return -1; + return AVERROR_BUFFER_TOO_SMALL; // Enforce total height to be a multiple of 2 if (h->rects[0]->h & 1) {