From patchwork Fri Jun 19 14:26:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 20501 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 98C4344BB6D for ; Fri, 19 Jun 2020 17:27:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E4AD68B6A4; Fri, 19 Jun 2020 17:27:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A26F689F05 for ; Fri, 19 Jun 2020 17:27:02 +0300 (EEST) Received: by mail-ej1-f68.google.com with SMTP id mb16so10417545ejb.4 for ; Fri, 19 Jun 2020 07:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=6BiX3WRCCXOiziFaXDb7ENslIr7Aw5e1WjdfqP6agg8=; b=GFTvtt1BRXLGe/RYsy7BsUYRM63qgw0R8SpzfhGOEsdiZ2gx0ZMGQHnYYL9ExTbGY/ 6CX0wrTBqz1WkdFuIpxi7+GKZnoE+m2On9AnGkz/im01Q2/qUXzDcqutMOrjfpW/B3kp lBn5awHIrbg+15Qr2FFg+1+uO2cppRM7m5yEGHRul0W6Af5FUIiex/mdb+PZrkkA++rg i09oTMqrFhXrolIDIiS0IwriKybq+1t1PNEx94/FNduEcd8JA6ipt8XZRPW82dBKbXBC S0OK/sLnqsKNYIJIWSeodbgz6rPGF3L6TB0wJZhmJApDl3VpwKxQVviaEKQ81wREa71J xG7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=6BiX3WRCCXOiziFaXDb7ENslIr7Aw5e1WjdfqP6agg8=; b=SpUfisR+HijhETteg4MjQr5QLsETdWQ3QGiDxV9oCRBJHdYTstk/Cc6APXPlJL/VK0 sZuceN/qbBvkmlv8msEd6RjTItOWp5I/64T+6Z3N4g3Mio9OwTFFXaZPCh2Q5xQveFXj yvH6U+faNNAOWGf5gYztYsUtaO1kQsn/XpX3jKOf3DFusXAFavpwg6e8moc07VKdDiwp ub1XvayzGERivHORkgHXHhQlgNdlKnYKFTR0EDbv4XFQBcL8qn4zuJGWk96nrfwU6wSt /TtfdvooeS9MZsgp7+Hs9JvjJ3ERNw06d29fzhi5qm6m5HJQUCGZShWkOGtohS690btE wclA== X-Gm-Message-State: AOAM530ti8oiSmUeCCKLMLCgRMepAsAZOFW2b3D62/ZlUkQHqq67RIJk 8nvAxNWO6OZbM3RPJ4qTMHkRnn9R X-Google-Smtp-Source: ABdhPJybTn8wcAyQBrJ/DkX3OfT4FscfVgUPKS/AoxGq8WKhEBGU3s9U9dqRDZQnMFxBg/5A76Trww== X-Received: by 2002:a17:906:6410:: with SMTP id d16mr4155031ejm.376.1592576821695; Fri, 19 Jun 2020 07:27:01 -0700 (PDT) Received: from localhost.localdomain ([37.244.249.74]) by smtp.gmail.com with ESMTPSA id a13sm4650212edk.58.2020.06.19.07.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 07:27:01 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Jun 2020 16:26:50 +0200 Message-Id: <20200619142650.16870-3-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200619142650.16870-1-onemda@gmail.com> References: <20200619142650.16870-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/ccaption_dec: do not modify packet data in case of parity error 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" To dissallow similar errors in future, make pointers const. Signed-off-by: Paul B Mahol --- libavcodec/ccaption_dec.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index fe6933ab5c..63666db852 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -341,11 +341,13 @@ static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch) * If the second byte doesn't pass parity, it returns INVALIDDATA * user can ignore the whole pair and pass the other pair. */ -static int validate_cc_data_pair(uint8_t *cc_data_pair) +static int validate_cc_data_pair(const uint8_t *cc_data_pair, uint8_t *hi) { uint8_t cc_valid = (*cc_data_pair & 4) >>2; uint8_t cc_type = *cc_data_pair & 3; + *hi = cc_data_pair[1]; + if (!cc_valid) return AVERROR_INVALIDDATA; @@ -355,7 +357,7 @@ static int validate_cc_data_pair(uint8_t *cc_data_pair) return AVERROR_INVALIDDATA; } if (!av_parity(cc_data_pair[1])) { - cc_data_pair[1]=0x7F; + *hi = 0x7F; } } @@ -782,17 +784,15 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp int64_t start_time; int64_t end_time; int bidx = ctx->buffer_index; - uint8_t *bptr = NULL; + const uint8_t *bptr = avpkt->data; int len = avpkt->size; int ret = 0; int i; - bptr = avpkt->data; - for (i = 0; i < len; i += 3) { - uint8_t cc_type = bptr[i] & 1; + uint8_t hi, cc_type = bptr[i] & 1; - if (validate_cc_data_pair(bptr + i)) + if (validate_cc_data_pair(bptr + i, &hi)) continue; if (ctx->data_field < 0) @@ -801,7 +801,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp if (cc_type != ctx->data_field) continue; - ret = process_cc608(ctx, bptr[i + 1] & 0x7f, bptr[i + 2] & 0x7f); + ret = process_cc608(ctx, hi & 0x7f, bptr[i + 2] & 0x7f); if (ret < 0) return ret;