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 ESMTPS id 9C5844BC2C for ; Sat, 3 May 2025 17:56:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B279687D93; Sat, 3 May 2025 20:55:48 +0300 (EEST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 50875687D93 for ; Sat, 3 May 2025 20:55:39 +0300 (EEST) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43cf3192f3bso29552375e9.1 for ; Sat, 03 May 2025 10:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1746294938; x=1746899738; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cSj/NIi006o4pON7+rE3ry8w41XrflVr+KezAumGPNY=; b=R8gLxp9MAgxsO/LdjWTmwdDhCzJVbdZoDfj5e+1Q7WAIq/p6H3tr2jrdP12XvoLwM4 W3iNcMj07t8cQTDO758izL0dcme2LV9JsKKuKG+wLsB7MLCVFQme1bNgICPBZ+J+UnAH LYOgydDXQSn2s4yXmvLlvxCGwcRb1EOhfXZmwRTvI0bkx6LdQi5bxCGfRaphq0z1pTdc jx3xGAGvUaFgKH4RcZhstCW/PGHdWzrueeZxxdFzeKyh9PpgEiMf3FKkDPH2Fx3IpyjO 4H5KmNsqbSgfrqOFKOLSwl34RVQ7+him2+PKKqQlBpr2eoXm2YrNuwtAalvoT2z4pIqK vV6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746294938; x=1746899738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cSj/NIi006o4pON7+rE3ry8w41XrflVr+KezAumGPNY=; b=LWUsZhTgc14Y9zy3yYFC8QqEqYv4b0YN2pLkEaLJj+TGyLpW3QpYOeda9eKj8/6/+s VlD9AnvGU0cZ012qaazjIwz/oUj6bX+Ey4hXZSFq+tH3Hpu3cyXHVHEnE+yCgeK7EeAO 2tvF1VrQxUIkTOECYQfaTBI6mohv/71p5jcdtpNYbGZm3ZqRUMYOG+kYRTkzs885nnmD fD2ufSybh6yQwx760+UnYqQ2soQeIpoX0N2v9ljtV2rMLpzXsiXLb7HWd8YF4VsthTkL kUZbrDiwNKLDDqJYyR0278sw2szr6QUtCRnvUYijpKMyNTwTcrGITYkdmXwzkMExLxFG Hu8Q== X-Gm-Message-State: AOJu0Yzk/qMeHIBAm4JgFjI54kcvaM8HuB0z3psQK+4vRAG6s/P8EHkI qKeB1fhmpNjOa0xCFM/O4fEGGwBOg+7TPICPnDr8sE+uK+/gk6oSjal01DfKjAc/N/flF0TqZgx fWXG1rg== X-Gm-Gg: ASbGnctMb3gJynm4SxdTkZd5dx5mShWrzw74ahnFs7HFwDn5U4AclqmKtyaLRGs3Ut4 Ir+ndr06KwBcRK8vqGpEkgekXRlxgObPK+EEu/9yiBaqd1U6sRxvwoMhq+Jb5qgi933R/dk4nic TJknFJuJjv3t8VyJ15zrNFOFR2myCZNIEyh44P+sfncnil7ant+m6rRlJUnOcFNDIEvmDnU6xiJ foxTSxfbu1HHcqekDM1qSUKwhUMuiBuT7nd8PzjAmMOhAaMWgb8YDNP3zDIvoMnM5ppPUtJaL8o r+8Yp4TjpQP0hUFhSF6n0LfrflwDZoySusT7ZJHNo40SG5ZhNG0FMihmLcWPQz0jXnWfHsEg9kc 8WALVoGP02Q/wUWehz1+uVMY= X-Google-Smtp-Source: AGHT+IFw20DqRJODrsBV+G+hIkxkED+GRQf5/Fh76EaCkwDHEAvR5zglDInLfK7ltaxQR25v/yO6bw== X-Received: by 2002:a05:600c:5027:b0:441:b698:3431 with SMTP id 5b1f17b1804b1-441c4948315mr11951505e9.28.1746294938460; Sat, 03 May 2025 10:55:38 -0700 (PDT) Received: from localhost.localdomain (cpc92320-cmbg19-2-0-cust719.5-4.cable.virginm.net. [82.13.66.208]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b8a3156asm80683645e9.38.2025.05.03.10.55.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 10:55:38 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 May 2025 18:55:19 +0100 Message-ID: <20250503175527.1517092-3-sw@jkqxz.net> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250503175527.1517092-1-sw@jkqxz.net> References: <20250503175527.1517092-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6] apv_decode: Improve reporting of decode errors 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: Halt tile component decoding at the first entropy error (this will be a desync and is not recoverable). If any tile components contain errors then discard the frame unless the output-corrupt flag is set. Also fixes CID 1646764, which is the error case where the tile component is too large for get_bits to handle. --- libavcodec/apv_decode.c | 52 ++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c index 2a59c9b25d..7ee39e578a 100644 --- a/libavcodec/apv_decode.c +++ b/libavcodec/apv_decode.c @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "libavutil/mastering_display_metadata.h" #include "libavutil/mem_internal.h" #include "libavutil/pixdesc.h" @@ -42,6 +44,7 @@ typedef struct APVDecodeContext { APVVLCLUT decode_lut; AVFrame *output_frame; + atomic_int tile_errors; uint8_t warned_additional_frames; uint8_t warned_unknown_pbu_types; @@ -121,6 +124,8 @@ static av_cold int apv_decode_init(AVCodecContext *avctx) ff_apv_dsp_init(&apv->dsp); + atomic_init(&apv->tile_errors, 0); + return 0; } @@ -150,7 +155,7 @@ static int apv_decode_block(AVCodecContext *avctx, err = ff_apv_entropy_decode_block(coeff, gbc, entropy_state); if (err < 0) - return 0; + return err; apv->dsp.decode_transquant(output, pitch, coeff, qmatrix, @@ -207,8 +212,12 @@ static int apv_decode_tile_component(AVCodecContext *avctx, void *data, .prev_1st_ac_level = 0, }; - init_get_bits8(&gbc, tile->tile_data[comp_index], - tile->tile_header.tile_data_size[comp_index]); + int err; + + err = init_get_bits8(&gbc, tile->tile_data[comp_index], + tile->tile_header.tile_data_size[comp_index]); + if (err < 0) + goto fail; // Combine the bitstream quantisation matrix with the qp scaling // in advance. (Including qp_shift as well would overflow 16 bits.) @@ -243,12 +252,17 @@ static int apv_decode_tile_component(AVCodecContext *avctx, void *data, uint8_t *block_start = apv->output_frame->data[comp_index] + frame_y * frame_pitch + 2 * frame_x; - apv_decode_block(avctx, - block_start, frame_pitch, - &gbc, &entropy_state, - bit_depth, - qp_shift, - qmatrix_scaled); + err = apv_decode_block(avctx, + block_start, frame_pitch, + &gbc, &entropy_state, + bit_depth, + qp_shift, + qmatrix_scaled); + if (err < 0) { + // Error in block decode means entropy desync, + // so this is not recoverable. + goto fail; + } } } } @@ -260,6 +274,13 @@ static int apv_decode_tile_component(AVCodecContext *avctx, void *data, tile_start_x, tile_start_y); return 0; + +fail: + av_log(avctx, AV_LOG_VERBOSE, + "Decode error in tile %d component %d.\n", + tile_index, comp_index); + atomic_fetch_add(&apv->tile_errors, 1); + return err; } static int apv_decode(AVCodecContext *avctx, AVFrame *output, @@ -281,6 +302,7 @@ static int apv_decode(AVCodecContext *avctx, AVFrame *output, return err; apv->output_frame = output; + atomic_store(&apv->tile_errors, 0); // Each component within a tile is independent of every other, // so we can decode all in parallel. @@ -289,6 +311,18 @@ static int apv_decode(AVCodecContext *avctx, AVFrame *output, avctx->execute2(avctx, apv_decode_tile_component, input, NULL, job_count); + err = atomic_load(&apv->tile_errors); + if (err > 0) { + av_log(avctx, AV_LOG_ERROR, + "Decode errors in %d tile components.\n", err); + if (avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) { + // Output the frame anyway. + output->flags |= AV_FRAME_FLAG_CORRUPT; + } else { + return AVERROR_INVALIDDATA; + } + } + return 0; } -- 2.47.2 _______________________________________________ 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".