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 AC5014B364 for ; Sun, 9 Jun 2024 15:06:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2E44368D5BF; Sun, 9 Jun 2024 18:06:12 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E3FEB68D3AF for ; Sun, 9 Jun 2024 18:06:03 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1717945558; bh=xnivrQdoXUIvGi23B0bkOv/Mh/I3PBEEBX5DC1niKlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FKqZOGfioja3NDYKTVSBc3VBq+Fsh/WZhorsSx2jxBoSucLHvIaAOBMbh/ypPV8eq CwKBtU2LBcTPZzuqyTcBJqDPH9wF2QA6E7S3Ras4x6dlBtulTAmOYSC/E3DwM5s1oF fOU9inmqyQPblppibGPuGb8kEbDxwBHdq2cXloxc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8B3E44418B; Sun, 9 Jun 2024 17:05:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Jun 2024 17:05:53 +0200 Message-ID: <20240609150553.72865-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240609150553.72865-1-ffmpeg@haasn.xyz> References: <20240609150553.72865-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] avcodec/dovi_rpudec: handle errors consistently 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 Cc: Niklas Haas 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: From: Niklas Haas Only flush state when we started parsing data, otherwise just error out. Remove the 'fail' label to make this a bit less confusing to read. --- libavcodec/dovi_rpudec.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c index e947870d45..72e4add618 100644 --- a/libavcodec/dovi_rpudec.c +++ b/libavcodec/dovi_rpudec.c @@ -123,7 +123,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, int n) if (VAR < MIN || VAR > MAX) { \ av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \ #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \ - goto fail; \ + ff_dovi_ctx_unref(s); \ + return AVERROR_INVALIDDATA; \ } \ } while (0) @@ -306,7 +307,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, uint8_t profile; if (rpu_size < 5) - goto fail; + return AVERROR_INVALIDDATA; /* Container */ if (s->cfg.dv_profile == 10 /* dav1.10 */) { @@ -360,7 +361,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, } if (!rpu_size || rpu[rpu_size - 1] != 0x80) - goto fail; + return AVERROR_INVALIDDATA; if (err_recognition & AV_EF_CRCCHECK) { uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), @@ -368,7 +369,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, if (crc) { av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc); if (err_recognition & AV_EF_EXPLODE) - goto fail; + return AVERROR_INVALIDDATA; } } @@ -439,7 +440,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr); if (profile == 5 && use_nlq) { av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n"); - goto fail; + ff_dovi_ctx_unref(s); + return AVERROR_INVALIDDATA; } if (use_prev_vdr_rpu) { @@ -453,7 +455,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, * out as this corner case is not hit in practice */ av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n", prev_vdr_rpu_id); - goto fail; + ff_dovi_ctx_unref(s); + return AVERROR_INVALIDDATA; } s->mapping = s->vdr[prev_vdr_rpu_id]; } else { @@ -462,8 +465,10 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); if (!s->vdr[vdr_rpu_id]) { s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping)); - if (!s->vdr[vdr_rpu_id]) + if (!s->vdr[vdr_rpu_id]) { + ff_dovi_ctx_unref(s); return AVERROR(ENOMEM); + } } s->mapping = mapping = s->vdr[vdr_rpu_id]; @@ -635,8 +640,4 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, } return 0; - -fail: - ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */ - return AVERROR_INVALIDDATA; } -- 2.45.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".