From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C598E460B0 for ; Sun, 4 Jun 2023 02:02:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 957F168C36C; Sun, 4 Jun 2023 05:02:30 +0300 (EEST) Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B5A368BF99 for ; Sun, 4 Jun 2023 05:02:24 +0300 (EEST) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-55564892accso2513263eaf.2 for ; Sat, 03 Jun 2023 19:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685844142; x=1688436142; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=vEssEWyR9gPK30SkRL5SdBqdcJFfemRI/tiVwJ46kzM=; b=UKMB9I4obNn4QTtFaOXCu27uYUWJrE8OnnwwxThhvUccNNFP1gaC8nkKULU3ji/Ckf foR8gAZA/ROfXycb46UZ8WLuyrTmtSSzX5cBfv8LwNDSDzxKavf7MSWl08NsKMrMjmVg djpjoDynpavIcVWNx5JF9hoyBZ4VXpy7x84d7Mwe+S9ZIGmVKSr98a7ww28OvoXnF1CJ jJ7K/J9NZ5yqN0zjTp0E76th7WsHdjk14fYOGHRTX67/VrVGx7Ai27fPYiJe+1ec2MnH SnkPYBnjPcSTfoGBHyj8IjTh68WxeE96JrrL/vf3d9LogG8uf9Hdw95iA/2ZO0MhDfiH 1llQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685844142; x=1688436142; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vEssEWyR9gPK30SkRL5SdBqdcJFfemRI/tiVwJ46kzM=; b=PMSCHk/9X9SyNIiDvI6cYsb84Wzq5h2pin0AMvAI3Q5DO2VABxVAZfjDs4PwrHPpMi jpQbHWvYnNJ3bhmCY8CIjNgGUU2b7dtdpad92/GEbQVA48QDVL3/+Bk/9RFVYxU86jOH 1BqVv6KMp/7WIOwaznwo02/KDdBT77KMbb06fSgfTyw3YK3o71Za7CisiGAuFdzjvFDB wBSKjVaz4UqO8YsbZa9TvSaiu4BZjlQ3HQt4s49r/jv3aDGFOnyngkT6PUyiMZ2TtfYv sAfg7D992XItzxZ9JRSQpNTaOuVLclAWjLr/osXM5OY1FIDt5B49v3cRp+gOpXWPWqdv 9ldQ== X-Gm-Message-State: AC+VfDz3HrDc/uuewQ+lrc90Se2Z9NCaKCJCoezCdv6XoU8rn2AbfOu3 hToSnmyzChQfNrqbIg0N04KXRqTuFdg= X-Google-Smtp-Source: ACHHUZ4M7+1Z6w9OQr8mcCRONHuab/V3xm5QaihrsqNqD8hEK5aMlnwpFBNnyuZ5SOZ0jvFaJLTnmw== X-Received: by 2002:a4a:4f46:0:b0:555:7d66:552e with SMTP id c67-20020a4a4f46000000b005557d66552emr10834274oob.2.1685844142224; Sat, 03 Jun 2023 19:02:22 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id x1-20020a4ad041000000b0054f6fb0ec57sm1930570oor.11.2023.06.03.19.02.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jun 2023 19:02:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Jun 2023 23:02:12 -0300 Message-Id: <20230604020214.1527-1-jamrial@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3 v2] avformat/av1dec: fix EOF check in Annex-B demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: And return any packet buffered by the bsf. Signed-off-by: James Almer --- libavformat/av1dec.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index 216d4e2298..79ad8a9411 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -124,13 +124,17 @@ static const AVClass av1_demuxer_class = { #if CONFIG_AV1_DEMUXER -static int leb(AVIOContext *pb, uint32_t *len) { +static int leb(AVIOContext *pb, uint32_t *len, int eof) { int more, i = 0; uint8_t byte; *len = 0; do { unsigned bits; byte = avio_r8(pb); + if (pb->error) + return pb->error; + if (pb->eof_reached) + return (eof && !i) ? AVERROR_EOF : AVERROR(EIO); more = byte & 0x80; bits = byte & 0x7f; if (i <= 3 || (i == 4 && bits < (1 << 4))) @@ -139,8 +143,6 @@ static int leb(AVIOContext *pb, uint32_t *len) { return AVERROR_INVALIDDATA; if (++i == 8 && more) return AVERROR_INVALIDDATA; - if (pb->eof_reached || pb->error) - return pb->error ? pb->error : AVERROR(EIO); } while (more); return i; } @@ -170,15 +172,15 @@ static int annexb_probe(const AVProbeData *p) ffio_init_context(&ctx, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); - ret = leb(pb, &temporal_unit_size); + ret = leb(pb, &temporal_unit_size, 1); if (ret < 0) return 0; cnt += ret; - ret = leb(pb, &frame_unit_size); + ret = leb(pb, &frame_unit_size, 0); if (ret < 0 || ((int64_t)frame_unit_size + ret) > temporal_unit_size) return 0; cnt += ret; - ret = leb(pb, &obu_unit_size); + ret = leb(pb, &obu_unit_size, 0); if (ret < 0 || ((int64_t)obu_unit_size + ret) >= frame_unit_size) return 0; cnt += ret; @@ -196,7 +198,7 @@ static int annexb_probe(const AVProbeData *p) cnt += obu_unit_size; do { - ret = leb(pb, &obu_unit_size); + ret = leb(pb, &obu_unit_size, 0); if (ret < 0 || ((int64_t)obu_unit_size + ret) > frame_unit_size) return 0; cnt += ret; @@ -234,19 +236,24 @@ retry: } if (!c->temporal_unit_size) { - len = leb(s->pb, &c->temporal_unit_size); - if (len < 0) return AVERROR_INVALIDDATA; + len = leb(s->pb, &c->temporal_unit_size, 1); + if (len == AVERROR_EOF) goto end; + else if (len < 0) return len; } if (!c->frame_unit_size) { - len = leb(s->pb, &c->frame_unit_size); - if (len < 0 || ((int64_t)c->frame_unit_size + len) > c->temporal_unit_size) + len = leb(s->pb, &c->frame_unit_size, 0); + if (len < 0) + return len; + if (((int64_t)c->frame_unit_size + len) > c->temporal_unit_size) return AVERROR_INVALIDDATA; c->temporal_unit_size -= len; } - len = leb(s->pb, &obu_unit_size); - if (len < 0 || ((int64_t)obu_unit_size + len) > c->frame_unit_size) + len = leb(s->pb, &obu_unit_size, 0); + if (len < 0) + return len; + if (((int64_t)obu_unit_size + len) > c->frame_unit_size) return AVERROR_INVALIDDATA; ret = av_get_packet(s->pb, pkt, obu_unit_size); -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".