From patchwork Sun Aug 21 01:29:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37370 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp585608pzh; Sat, 20 Aug 2022 18:30:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR7SevKK5sM+8zYVcR4lchkroH6qSujb0dGdnX7tQDWZdYdcfN5Jdtvghv0smMD9UC6QT+1X X-Received: by 2002:a05:6402:2791:b0:446:1ce0:f796 with SMTP id b17-20020a056402279100b004461ce0f796mr9773358ede.44.1661045416043; Sat, 20 Aug 2022 18:30:16 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i21-20020a1709064fd500b00732f76a97aasi5751112ejw.899.2022.08.20.18.30.14; Sat, 20 Aug 2022 18:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=VQ99hsuS; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D95A68B9B5; Sun, 21 Aug 2022 04:30:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [40.92.75.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F254B68B984 for ; Sun, 21 Aug 2022 04:30:03 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4q/5t2grdIxvRtPJdrq73XxKvZopn0aoChHyk0DTkIrEInhkcTho9YTx/7tpg1IUvx++onH7zZauLkUVgr1/AY82M1Ikx3Dwb9cCQ70L22pdwupW26CiwEOZZoJSkNowAqcY2spI70rSLZrXgZzShS8m54ARrXgLjbIomLbdUTrUW8tMehncD4vM87WSKYkM9S1jMMNd3JG8FA40OyvQfZzvr4OOa9YK5tN+iHWQSeFDNWcrdP+1sABlvywiQ0RBFXkzuRN97E1vGi3jjK5o9jHcEAW1z910qXxtgRFjPeJmg9CzLRsL/rKsZxcEcGDK4hpDIV2WfRiIJQ7zhuj2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/b8n18hHC0b8c/TiYAK9y9z5dufBAJm7FDO4zUO7opE=; b=cCK/4PF1dwCib4SgdspxTkyy5DlZ0xCDjOrnQOf/ACSmncmDp8zI8cQ/sB//j/0qUgzFNOHg5H1XO4hyUtAK9evlzIu50GG2wf3zbxi4Cigg6PelXP33w1YEJXOwRAjDOdjXu+J154c0nCGzvDs5Ra7zMyHBlPcSKFbWIld+3BtpnAHnsE8oIChE2XJjkaPUi5Qymbz7GOQQAl8LGLMvLD5Y+Ny1OR9cNdmLVR32BGA4bmmGqWJ2v66nR4KFOxXk+86s2hKx9pLuNesq2BYAep/6cHH0CcanJoiADi1cQ2mEqoP1vMxAzpkrmK6QAOO7/Ur7RT0fkChQmZxkmsnfWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/b8n18hHC0b8c/TiYAK9y9z5dufBAJm7FDO4zUO7opE=; b=VQ99hsuSR0zTrwA1a57VLsP01l0ixrR8Uzy6mqsYlOF6ydiqVQjEjEsas2J6UZkNq2GoCK/Q1EdFIa89vw7kpT6AXWLYWQ3BpzTdw/Fyz8VGAQhzfLu/7WijDmifcXJ0GbfSemiyFPH82Ov7OA+HRMTR/vM6eVImKNBLn9KQQzmLM+Jc0SM+eX4lylg4EFROjfEDcgeEWPKZhCLv1rr7ge6kPFGsUVx905pTeZmSsJyrh6k6ZVbTgzbk3d5/ENA7dcT/e/ehlio/b/F4DQGEWdFwxsDZQx6te2tPuO+hmbLSHbT8QP07AhYDmcbz+OsZpY1DTCU+YMEOo7t/LiX3/g== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by DB3PR0102MB3642.eurprd01.prod.exchangelabs.com (2603:10a6:8:11::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Sun, 21 Aug 2022 01:30:01 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46%11]) with mapi id 15.20.5546.021; Sun, 21 Aug 2022 01:30:01 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Aug 2022 03:29:46 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [Q+xhTpwVnta/LANchWUFNXz85gkrMwtk] X-ClientProxiedBy: ZR0P278CA0174.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:45::20) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220821012949.1345479-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 122e9f0a-223d-41b8-7907-08da8314aa62 X-MS-Exchange-SLBlob-MailProps: ZTmCor6bjd/ba3iRGhhtxD+cx0htDG6A5bgC7ESQbi70tsqqIDz2mcyVqVevAMlabjg0Rl5FnaDgiROlai3/aFbOybjrvI9GztlUBc0W6hCdXFbzkGfIblBFAqeh6SxNEN0n0T6ceq4Jo9ZDN+FpIe/snZ1hczd4bTXb4ubHJSD45F+F7oNkriHjZrjuHPvyqUE5TXY7ofcG8Ng7MUZfR2wD0rfrpiSIkrNQLPRJooajnpwNsfmhuN1SwEa/GSjqUIIPKCfPNPVMrTSFFe8VzZ7kdDiKlwazN3nnxJyOQTvbc3dzuzN/J1+ooi30jXD4/x7yQV8F/hgemb2UAh8dUZnzl9Ohye5WxaAjMxDuSOmbFg++mz0EKbgU9DZjwlIvTQmu3JOJXe3OeEg+RxXcqd3gOXIMs1BWaffIx9wCFCTjtzwBIraKKnDDDVO1aOa98TQMyblOnCVMgQTmQihkRXuJTjXbDLa62f6cEuI5nW7OXxNDc0nWLXEZfeuWAGEBGei1qKFt2FyLewz0gs0/FWSGcO92ZnS4pdaFYAmDrr87YLQDSI8tMOqXFXlq0VbtTMU7qsHVUtnSqV/lAhFd0bSGiaYjVekW+1nGwwaD5pGBruxctGmZqMlbNABeyCSG22aU2DbLW7UtIAW/OX+OaTihtdS8Mcw4kc3fdaJhya1ww/Uyl9O9RSsl917Ch6GlYvjUOaDVvYZL1XpuF+p3blHW1fAxOH6RaUS+gmWow04Gd5gjiQ3TaGJ1MZXd8reYNfiNnLWLIS6CrG6oFKv8OWmwL+JoIPjTF6S80zIud1YmD8MmJg59AkWGknLJiu5C X-MS-TrafficTypeDiagnostic: DB3PR0102MB3642:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gidXlQkEHnV9+RPI3X67zhMq64MJnceea1p3VRf++ot5RwzeECjtmD26iXNz1n7FZwOWGCpuFvsdL64lfnfngFkGrhVFTnrdIjyJB1DlvlaOwjl3ORSiZACAjoxgn67lhrmHSBWrpiPpJKJ1BjyUdP2K0yHoDWFRCOwpH9YmZqw0Ut7Z0BRVjHqWZkpUN6miovbdtdpOET0kOCB3I21KXchWmWqEwz6uNq03gqikmOvOkJcjrpfqV9bAdYGTmBaBPTmbcMjnAPPPvHI4AS7snc6E31OozRK/Bmzzvl13TH74YaxIldmgFcmKsN/nfFUfh4TpIFOmfpnbP32pXhIc3zyB19cl1AbtW9ufWpRM2oL65Yecad0oivgHfhpttHrQtjQUrYaX5yDB8h8DC20i8xd9BMriSSRu6E8gi6X548bo26ATEUcGa0QrJ5ZBebCzEAkjgQ7cicfvDgUcBvriO50M8Zo/3+nZT/UJDcEqaR5A5XlxYfllQHy2wCZK1njSo8P34Bob0eVl4RWg92n/W92hfua+zTivHoeeBrnUUj8mC5YewOXDH9RG8YojUGhWNu+/tptXCljQlqEQPLZATEZBYRyU8GwC+j/Y2fXK6mEIX7i3nzjPngxgYtSjScRVRuRVRDvb9vRdwOdd0BgJjw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GQXe7nU05a7j9OpC3Y45jEVoPpkXmeBpHPqrkpivxIs+Fkw1nVZcXpuFxLx4YUPcUXVb9K/k8tK1Ru1d6IYArvnCpAMJ6baLA65CoZuQctvEdy0wglETbVWdaV96GgzKXqmX4C2bAWnOnYfcdlG3TumasxvEpxGctB7R3UBj898N/QddZwPYDofYOG/WidGAY8AyuVEEPoDA8uGnXmHhF0Am+SKUfWxxWqWp3eGkX++txMq7OidoDgUUQHrAiVW5k+77/3umZkjGQODYmjxVjFXKSfFkXPY8FXErg1fv6A/uqWezowkVa6d06/+dNnyJ5+q54+V6khV4NWMx+Kc4Ic5hWT/i5EsgMoXDDeEP6gTcndDPxWtGQjE9tQ3GIHNP8AEFp+4jg2q48dQOfj5UoXJebAvoomd4DmKp695Nz7kyUIprVkfn3MwJJKa6ARarAjfvqVsYu05bTkxFovcqhYpDIxFf5aBaHmJxWarDHziNG27Hb6E4VBfXErKvwo86d/J4MmbFzMJZda2Zx8cqMQ/tnvf9Bp/urP99M95Htvrfd8avGdjby9EgwfvyIivKTlCkiFnOWRxX3FB3620Lh7uF/dQKfEeX0CM3yzgePfZb0qjm636onrkw+k3q7mdt6U1JXO9+rWg/hwXBXp77H8/NOB2r8q3zLb4ZohMRg9GcA/rCgBE/t1TJvny4qizuq1ldvHqdWnUtwj+KrkqMXQ4N2O+nGvKx7NTSEiMa0IIQd5b7h51Mi0k8L7MaGH6/eVNhpJlNMjgJ5HGw5Rix0QoKtnfWy7gWSbn2y2TdrsrM0Hp/YEthbC/i/ZUAhIzVtX4ogs2+B33Vy0RPONASbmyBjrUPS03K/zb5mJ9CxAl+OhXxmm/9n/ZVpVI3/a4e9usRz78MzejmhHO+fa4mx3m0hoTb7l62oDP7cNSiN2OMI1DZpft+qP5Hv+NTznHTLYC/4B9Xkl5IFdWNzSYs0Io9A1nFH2M5M+EBJEQm3wbpDW7SLIGIZa0NP56GjSMmTgtgqdgJE9guLgp28l9xF3wkVGEsJ0qKUtfkANZUiOs5esuaEM4xPlLsfSIcgobjDve6WZnATj+b+p1N0nhz/i4sqLe1V0/sSyHd/1Fk+CQen3FlwdTItFnzvtKNG3HI+0GXlkAAvRYZ7m4t8CXU1fiv/sN8FsJOTVzLgsXBazQ0540iRyVsQ3GzKqO91iWR/0+hIkNwrVlt7/OJC7890MMchOokiB+mW2OjwG5YKySgS6/uoqDkuyQqn3pR8PJUedGnTjSiGtsvi0db6rtG1mIulgJir9JAAp/FiFFmljY= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 122e9f0a-223d-41b8-7907-08da8314aa62 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2022 01:30:01.2979 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0102MB3642 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/pngdec: Fix APNG_DISPOSE_OP_BACKGROUND 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FSSZUs2vRyCg APNG works with a single reference frame and an output frame. According to the spec, decoding APNG works by decoding the current IDAT/fdAT chunks (which decodes to a rectangular subregion of the whole image region), followed by either overwriting the region of the output frame with the newly decoded data or by blending the newly decoded data with the data from the reference frame onto the current subregion of the output frame. The remainder of the output frame is just copied from the reference frame. Then the reference frame might be left untouched (APNG_DISPOSE_OP_PREVIOUS), it might be replaced by the output frame (APNG_DISPOSE_OP_NONE) or the rectangular subregion corresponding to the just decoded frame has to be reset to black (APNG_DISPOSE_OP_BACKGROUND). The latter case is not handled correctly by our decoder: It only performs resetting the rectangle in the reference frame when decoding the next frame; and since commit b593abda6c642cb0c3959752dd235c2faf66837f it does not reset the reference frame permanently, but only temporarily (i.e. it only affects decoding the frame after the frame with APNG_DISPOSE_OP_BACKGROUND). This is a problem if the frame after the APNG_DISPOSE_OP_BACKGROUND frame uses APNG_DISPOSE_OP_PREVIOUS, because then the frame after the APNG_DISPOSE_OP_PREVIOUS frame has an incorrect reference frame. (If it is not followed by an APNG_DISPOSE_OP_PREVIOUS frame, the decoder only keeps a reference to the output frame, which is ok.) This commit fixes this by being much closer to the spec than the earlier code: Resetting the background is no longer postponed until the next frame; instead it is applied to the reference frame. Fixes ticket #9602. (For multithreaded decoding it was actually already broken since commit 5663301560d77486c7f7c03c1aa5f542fab23c24.) Signed-off-by: Andreas Rheinhardt --- Btw: If we had a function that only references a frame's data (and leaves the dst frame's side data completely untouched), we could apply the side data directly to the output frame, making 8d74baccff59192d395735036cd40a131a140391 unnecessary. I also wonder whether the handle_p_frame stuff should be moved out of decode_frame_common() and in the codec-specific code. libavcodec/pngdec.c | 98 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 3b888199d4..8a197d038d 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -78,11 +78,8 @@ typedef struct PNGDecContext { enum PNGImageState pic_state; int width, height; int cur_w, cur_h; - int last_w, last_h; int x_offset, y_offset; - int last_x_offset, last_y_offset; uint8_t dispose_op, blend_op; - uint8_t last_dispose_op; int bit_depth; int color_type; int compression_type; @@ -94,8 +91,6 @@ typedef struct PNGDecContext { int has_trns; uint8_t transparent_color_be[6]; - uint8_t *background_buf; - unsigned background_buf_allocated; uint32_t palette[256]; uint8_t *crow_buf; uint8_t *last_row; @@ -725,9 +720,30 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, } ff_thread_release_ext_buffer(avctx, &s->picture); - if ((ret = ff_thread_get_ext_buffer(avctx, &s->picture, - AV_GET_BUFFER_FLAG_REF)) < 0) - return ret; + if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { + /* We only need a buffer for the current picture. */ + ret = ff_thread_get_buffer(avctx, p, 0); + if (ret < 0) + return ret; + } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) { + /* We need a buffer for the current picture as well as + * a buffer for the reference to retain. */ + ret = ff_thread_get_ext_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF); + if (ret < 0) + return ret; + ret = ff_thread_get_buffer(avctx, p, 0); + if (ret < 0) + return ret; + } else { + /* The picture output this time and the reference to retain coincide. */ + if ((ret = ff_thread_get_ext_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF)) < 0) + return ret; + ret = av_frame_ref(p, s->picture.f); + if (ret < 0) + return ret; + } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -985,12 +1001,6 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_INVALIDDATA; } - s->last_w = s->cur_w; - s->last_h = s->cur_h; - s->last_x_offset = s->x_offset; - s->last_y_offset = s->y_offset; - s->last_dispose_op = s->dispose_op; - sequence_number = bytestream2_get_be32(gb); cur_w = bytestream2_get_be32(gb); cur_h = bytestream2_get_be32(gb); @@ -1086,23 +1096,6 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, ff_thread_await_progress(&s->last_picture, INT_MAX, 0); - // need to reset a rectangle to background: - if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND) { - av_fast_malloc(&s->background_buf, &s->background_buf_allocated, - src_stride * p->height); - if (!s->background_buf) - return AVERROR(ENOMEM); - - memcpy(s->background_buf, src, src_stride * p->height); - - for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; y++) { - memset(s->background_buf + src_stride * y + - bpp * s->last_x_offset, 0, bpp * s->last_w); - } - - src = s->background_buf; - } - // copy unchanged rectangles from the last frame for (y = 0; y < s->y_offset; y++) memcpy(dst + y * dst_stride, src + y * src_stride, p->width * bpp); @@ -1171,6 +1164,22 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, return 0; } +static void apng_reset_background(PNGDecContext *s, const AVFrame *p) +{ + // need to reset a rectangle to black + av_unused int ret = av_frame_copy(s->picture.f, p); + const int bpp = s->color_type == PNG_COLOR_TYPE_PALETTE ? 4 : s->bpp; + const ptrdiff_t dst_stride = s->picture.f->linesize[0]; + uint8_t *dst = s->picture.f->data[0] + s->y_offset * dst_stride + bpp * s->x_offset; + + av_assert1(ret >= 0); + + for (size_t y = 0; y < s->cur_h; y++) { + memset(dst, 0, bpp * s->cur_w); + dst += dst_stride; + } +} + static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, AVFrame *p, const AVPacket *avpkt) { @@ -1434,6 +1443,9 @@ exit_loop: goto fail; } } + if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) + apng_reset_background(s, p); + ff_thread_report_progress(&s->picture, INT_MAX, 0); return 0; @@ -1456,15 +1468,10 @@ static void clear_frame_metadata(PNGDecContext *s) av_dict_free(&s->frame_metadata); } -static int output_frame(PNGDecContext *s, AVFrame *f, - const AVFrame *src) +static int output_frame(PNGDecContext *s, AVFrame *f) { int ret; - ret = av_frame_ref(f, src); - if (ret < 0) - return ret; - if (s->iccp_data) { AVFrameSideData *sd = av_frame_new_side_data(f, AV_FRAME_DATA_ICC_PROFILE, s->iccp_data_len); if (!sd) { @@ -1515,13 +1522,12 @@ fail: } #if CONFIG_PNG_DECODER -static int decode_frame_png(AVCodecContext *avctx, AVFrame *dst_frame, +static int decode_frame_png(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt) { PNGDecContext *const s = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - AVFrame *p = s->picture.f; int64_t sig; int ret; @@ -1555,7 +1561,7 @@ static int decode_frame_png(AVCodecContext *avctx, AVFrame *dst_frame, goto the_end; } - ret = output_frame(s, dst_frame, s->picture.f); + ret = output_frame(s, p); if (ret < 0) goto the_end; @@ -1574,12 +1580,11 @@ the_end: #endif #if CONFIG_APNG_DECODER -static int decode_frame_apng(AVCodecContext *avctx, AVFrame *dst_frame, +static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt) { PNGDecContext *const s = avctx->priv_data; int ret; - AVFrame *p = s->picture.f; clear_frame_metadata(s); @@ -1608,7 +1613,7 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *dst_frame, if (!(s->pic_state & (PNG_ALLIMAGE|PNG_IDAT))) return AVERROR_INVALIDDATA; - ret = output_frame(s, dst_frame, s->picture.f); + ret = output_frame(s, p); if (ret < 0) return ret; @@ -1646,15 +1651,9 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) pdst->compression_type = psrc->compression_type; pdst->interlace_type = psrc->interlace_type; pdst->filter_type = psrc->filter_type; - pdst->cur_w = psrc->cur_w; - pdst->cur_h = psrc->cur_h; - pdst->x_offset = psrc->x_offset; - pdst->y_offset = psrc->y_offset; pdst->has_trns = psrc->has_trns; memcpy(pdst->transparent_color_be, psrc->transparent_color_be, sizeof(pdst->transparent_color_be)); - pdst->dispose_op = psrc->dispose_op; - memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette)); pdst->hdr_state |= psrc->hdr_state; @@ -1705,7 +1704,6 @@ static av_cold int png_dec_end(AVCodecContext *avctx) s->last_row_size = 0; av_freep(&s->tmp_row); s->tmp_row_size = 0; - av_freep(&s->background_buf); av_freep(&s->iccp_data); av_dict_free(&s->frame_metadata); From patchwork Sun Aug 21 01:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37371 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp587374pzh; Sat, 20 Aug 2022 18:37:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NQrr3AJI0KyB0U/WaT6i4MpCTF8pHEfNaKYbCH4WPpD5jhQZvMKovxr/ZO73gzN0o8hVS X-Received: by 2002:aa7:cd58:0:b0:446:d:905 with SMTP id v24-20020aa7cd58000000b00446000d0905mr11187637edw.191.1661045837153; Sat, 20 Aug 2022 18:37:17 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gs7-20020a1709072d0700b0073097d4bdb9si6530249ejc.681.2022.08.20.18.37.16; Sat, 20 Aug 2022 18:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b="uGP/uvvt"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A8C568B9AB; Sun, 21 Aug 2022 04:37:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067019.outbound.protection.outlook.com [40.92.67.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1FFA68B45F for ; Sun, 21 Aug 2022 04:37:07 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=khvtblz2lLMyW4cTeITi4yjW+LQBRFw5OcnVougBPSledk5AK5JJc53ZAZ0fZJrFFK3rkrdwKj6S2SdugY1eltWmtiO8sDKUOZXwfy9v5TPbamHKGojN3yCIs/wJEjIZ5eFRNM+zJmASFbyDFtWOlgyb4tf8pgIJ0kBodDvJwv2bovOC8v0rFF9apI2dVDowmGq6FeiJOYU6vCw25neQ8moswoJgbOfCgCFmCnYWHMRRM1JF+EjjylhKAhjp4IyJzBTvnphQWaBSZzAuSSP8yvweEiJZwDf+r9Cvk5phA2oZTUa2MncTIMbLAaosEFy86ZFnxhSEx6xTK+7CjQhsjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cP6Lia3jGEevPh/93rKCrn2EcM8Dcad5PFoCdK3MZlY=; b=Ayq+yJqlbaPmJAIpHYAgle07GjZgA1er5fpQDOG7VdIHBaSyJMkUeCyo1Q7EHUPaAzTrHpd1laQQn6OIdfw8kphORmh6vVxTvGXgPbzSrbl1W387X9717AFlH8Q1MiWkxq40CQOb6UH+w2Qx9INE8l0EMqFM+wMPMf+tVsBDV1n5hCEabRgu5av7ONLQ5c+H2naowE1DsD1V8ZBsapyb+nuWdHHGOu4gNMXGCily2ui5NZz4rYH4r7M1XJvu5O5mtbDFe/ly6b0strhKcr3gyVzs3E9EA0xrna5b1N0ybVj434Um1KZ//lKpIoAA2NQEjRzo3GoVYNoQ3RZmD09U1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cP6Lia3jGEevPh/93rKCrn2EcM8Dcad5PFoCdK3MZlY=; b=uGP/uvvtli1t+YlGpR76NLkOIY39tAO8Slz3q9KM2z78Je0n97T1Bg66hUPp/3aM4WwQfXq6e3SQe6YD3fh2xzt7hiqQXoBs5+zCjmh0CUbWE2FURdcMGd8ykNlNbk3Hsb/oa79pLbKU8Qla4inYTNj9r9T7HpoXfaN1o9WCaiZSrpsHft3GsAA9Ci7OEEf/yYz6RmscbUeh7IBo/FFYv4UHOKEnvYzpRQ/bpdoyEzNVCfvL9PvPq3ELmvY+lSuP+RxUnPVwGT9aZRPGmtgxnz78XrTjKJF9PO0UIy3g4qJKpXZd4Ud4OxEr73yzx315sVldg5UmCtDWmH87Z6EbCg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AM5PR0102MB2819.eurprd01.prod.exchangelabs.com (2603:10a6:206:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.21; Sun, 21 Aug 2022 01:37:06 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46%11]) with mapi id 15.20.5546.021; Sun, 21 Aug 2022 01:37:05 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Aug 2022 03:36:54 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [oEtUVG0nMVHrox/fJRAvwQycOW7lU/7z] X-ClientProxiedBy: ZRAP278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::15) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220821013656.1345943-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6df2d139-bb4a-47ea-d624-08da8315a790 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSZafVhYkhL3mEj/gWHL/2XXIRDV4OC3iaTnA0zMAnSIs2SiI8lh3U2R3kXFCxz7zjpbQxC38ENO1d1tIWCsN2OIXPAbBt097OCpWu333NFaAupfIw/akBJg6HTxoGb12aZpoyprgex/wJ8hphesLdatqHwU9sK+7JSfRc6yTH00iN0K58JiyU6BExYamBkeGSaQi22v+pxETosbHaJMCYV5bp8Bj0jYrmdKeO1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SJy0hU9KgUFGDXs1oClK79CrZFEtWYbwN4LHi51G8zGkoeyj4/5C3tTVSHVwA2N1dkW4YzEcPGIB3ObaVaAp7j36JykOr9JuiWxdlQCWOJ3gawvtGW81kxW4hUXNaLQbRMHpDCDPE9K4G/tVFOr3MTwscNYJSUuiSqo88Z4flRmAi8LWtxZ7FoDKOBdraFI0bLUV8CNC/zUfjvJu3MiyT+DrGRI9DN7CLgLsIcHG576jxNtR8HVGLkHgHLpCuZWNGgs8q7c9G+317Y3RWzno0AgZAcNaiomyxFWHz5vAIZ5NVSVXhVgMjAiMpf7M3YvM3lTTQ8zkUiV8T33O3Qlvs+qYN2dmIUGVocvSfe3TVFF9sY3JYQ9NUcnwPm18km0n+qAxhN6WgFkUNdpwngHtU/ojR0id++sLkSw4TmMvu4/MMcUhvLvQn0WAmRi+BAoRN7i0A9pHcVqxWeor1jOJ3YN2xovCqAnqQRIUUdiy/HQz2LEMktOU= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6df2d139-bb4a-47ea-d624-08da8315a790 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2022 01:37:05.8935 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0102MB2819 Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/pngdec: Use internal AVBPrint string when parsing chunks 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Aj2UeKD+S8YQ One saves an allocation in case the string fits into the buffer. Signed-off-by: Andreas Rheinhardt --- libavcodec/pngdec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 8a197d038d..189c3eee89 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -543,10 +543,8 @@ static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse return AVERROR_INVALIDDATA; if ((ret = decode_zbuf(&bp, data, data_end, s->avctx)) < 0) return ret; + text = bp.str; text_len = bp.len; - ret = av_bprint_finalize(&bp, (char **)&text); - if (ret < 0) - return ret; } else { text = (uint8_t *)data; text_len = data_end - text; @@ -554,8 +552,8 @@ static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword); txt_utf8 = iso88591_to_utf8(text, text_len); - if (text != data) - av_free(text); + if (compressed) + av_bprint_finalize(&bp, NULL); if (!(kw_utf8 && txt_utf8)) { av_free(kw_utf8); av_free(txt_utf8); From patchwork Sun Aug 21 01:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37372 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp587412pzh; Sat, 20 Aug 2022 18:37:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR5XtktCVqs3Rd1c9ejZX3Ln6NI9UHEsx31yyI5QfVo/PlZVDRd9FxkrMawFLv8Ta1gPuP5E X-Received: by 2002:a05:6402:3698:b0:446:6a7c:43de with SMTP id ej24-20020a056402369800b004466a7c43demr4405926edb.414.1661045845175; Sat, 20 Aug 2022 18:37:25 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g12-20020a1709065d0c00b0073101e55d9fsi6821182ejt.797.2022.08.20.18.37.24; Sat, 20 Aug 2022 18:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Ridy7Boc; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A97168B9BD; Sun, 21 Aug 2022 04:37:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067019.outbound.protection.outlook.com [40.92.67.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D779968B45F for ; Sun, 21 Aug 2022 04:37:12 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ah3GEaE7ml38wMZuJFbQI9TvyJBgiUBrLszDOOQep4yyIJPLP4Fn6SytYeeuZmUhsXkpbOXBeSaMlUdaxbo6GXsO4cPa6AIC3n5XR34MU731YUmGGcdkK6eKMDMiGDAQG1c2eDEBAAPfwZ3D1N5elTDDcAe+cLymR2zkzxBUwtlKozhzcRha2k+J8z8wdDp1ncB6bvT+TyFJNl0uam/59VGkmeQTn/EJRj3e8eZYMCgmTYMvz+XKLyHxYWdnfigRV9c35UkjNsASDS7YIJZxKFXtuZv4ICzDpm0bp8IYV/2YplzYjT3Uw3Mwn6EoqJS9hGe5bWoOdjWxV1Msk3EmYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ntLa0gQ15E4iujm2UWvLNGX+Y9iWTiyFcuLgPtCHMRQ=; b=DbKxF8IxyRWpzKA2gDeJz5fydaDjeHIblbRb6MXJlaIxbKRtyI1ATo04mHBLTbZ7Ohx4KDiBFIgHSezBSIsQmmcdALOFe3PHDsxDyPuIhl9gx9YXhZCTEyULB3EmBax+tp5mGmd2gdGT5Ljnz7LYoZuVNLCw8DRia+BxfmSUzq6Q944SvSnTEag9brec0K4/AyC1qsTWX5iKYucqTaadlHOFtc6WLN+5Yv6Mti5Ei8NEpUzZJI4HjlW5BKTmGkdqqjxCNpWRXnhNQmDOsyNjuNUXw8l1YIx/qdMEwFbk0iiSjpXObqlUVX9RaKXtD9qMZE9yZBW7lqAdF2SqIxIy5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ntLa0gQ15E4iujm2UWvLNGX+Y9iWTiyFcuLgPtCHMRQ=; b=Ridy7BocS4ch6WJGMWQFZl/LLTGtLUbvDp3JY64Ej7+UsLwlIiAmYQDjB9SmR4DxSDkMx/qBtOQMwBDTb+w88ziSqz5StZUj3EmSibjfqtA56IL8iJrub3qoJElXijZnNAYX5xZT45oheN8ON19Gz5RyKNDjz1XYCz7H8jXPEE0mDLkRt6/gh00kRhP1TjjZvNeL+OK6gB4DpLsQyiFvq4J9KLXh5KQkIFHb6edV/Kt8Kv5B8yJJneEqccKLvlPyrtIO+FMHlKMphoLKqcLbRAwPxnUKI14iazfJKAAlEFcPXihmBf3yzlBOaM+oDw0gMOZIkN593EXo0ul0ZTRqmA== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AM5PR0102MB2819.eurprd01.prod.exchangelabs.com (2603:10a6:206:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.21; Sun, 21 Aug 2022 01:37:07 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46%11]) with mapi id 15.20.5546.021; Sun, 21 Aug 2022 01:37:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Aug 2022 03:36:55 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Q2DF5IJtpBlvTiBPawJDfHLC9pxhVW/Y] X-ClientProxiedBy: ZRAP278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::15) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220821013656.1345943-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8fc06613-1ccc-47e4-8aab-08da8315a88d X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSZafVhYkhL3mEj/gWHL/2XJ1JLbF7FXYZy+HWFF+kayiHF2IkOOGcF6oMMyWQtVeTK3ypohd7XWni+5HxnJ+IdxPJRIRSeh/fw6aQycnDyXjxE5K0YwHI41oBmfUaojVDvZKsMJyt5eA/gxFA1xiLUL/WmJ2gK8iQy2lxEjXTtO59Ue1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UnnxwwZVl9uskAdhIicKKk/UsP5N+Kkep80ZzIyLanQEp7p3/2cwAiXN8ZRe0MOamCRKXhoXPu5E9fQEaVeCfejO8GUC4MZNen+OBYXjaaL+t5qwRsBhJf9QMMHZJvIq2ZKA0FSYXdtJyL/Y+OL/dyPbZqaWzAlJaLHghn2tqNE8/iLBa1C1o7okgU3r/pIDdE1jIxNGzFOYPjHyb0i/SjlEEL0HdEgpKsHp7JrZVmLzT80etEalQe9SGzm/AyE+wUyv9qcE+CLomkkE7FQ73q9gDEjkjiHE7kfnzl3gKqUSBDQqulm5g6leF/6nfKGACMOJE5gAxekE2ffMltrqOFiFxegZXd/x5Pe2lXR84TUxFUij9JRRz3OlnTYpnASVxkOQRI6giJ2/3gk4Dy7XFQPeL5yUXmpkfjco/UbuW6hiAB1LAHr8i+Y+Hzl/tnpRaNxaEhSXgPCGAv+bcHuB5NtfdX1h26nQcE1I4KAfLhYNOQJSpXWZPFRrv+Ok1U3dId596mh0VpNronQ0KlxRsXHEm7rftzWQ= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fc06613-1ccc-47e4-8aab-08da8315a88d X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2022 01:37:07.4559 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0102MB2819 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/pngdec: Use char* instead of uint8_t* for text 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nP4fiDZMw7Yr Also stop casting const away. Signed-off-by: Andreas Rheinhardt --- libavcodec/pngdec.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 189c3eee89..132ad40dc9 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -496,20 +496,20 @@ fail: return ret; } -static uint8_t *iso88591_to_utf8(const uint8_t *in, size_t size_in) +static char *iso88591_to_utf8(const char *in, size_t size_in) { size_t extra = 0, i; - uint8_t *out, *q; + char *out, *q; for (i = 0; i < size_in; i++) - extra += in[i] >= 0x80; + extra += !!(in[i] & 0x80); if (size_in == SIZE_MAX || extra > SIZE_MAX - size_in - 1) return NULL; q = out = av_malloc(size_in + extra + 1); if (!out) return NULL; for (i = 0; i < size_in; i++) { - if (in[i] >= 0x80) { + if (in[i] & 0x80) { *(q++) = 0xC0 | (in[i] >> 6); *(q++) = 0x80 | (in[i] & 0x3F); } else { @@ -525,9 +525,10 @@ static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse int ret, method; const uint8_t *data = gb->buffer; const uint8_t *data_end = gb->buffer_end; - const uint8_t *keyword = data; - const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword); - uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL; + const char *keyword = data; + const char *keyword_end = memchr(keyword, 0, data_end - data); + char *kw_utf8 = NULL, *txt_utf8 = NULL; + const char *text; unsigned text_len; AVBPrint bp; @@ -546,8 +547,8 @@ static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse text = bp.str; text_len = bp.len; } else { - text = (uint8_t *)data; - text_len = data_end - text; + text = data; + text_len = data_end - data; } kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword); From patchwork Sun Aug 21 01:36:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37373 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp587450pzh; Sat, 20 Aug 2022 18:37:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ua/ouDbyN5qKxGWpU29Ppmgq5C/LMsHzWRQuftXUMkGHLU7FSmtP+gUTLmmMZpiKBTBiG X-Received: by 2002:a17:907:2c41:b0:73c:931e:5179 with SMTP id hf1-20020a1709072c4100b0073c931e5179mr6857852ejc.42.1661045853108; Sat, 20 Aug 2022 18:37:33 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h6-20020a05640250c600b0044660f40ed5si3813722edb.256.2022.08.20.18.37.32; Sat, 20 Aug 2022 18:37:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=DxWlPo0r; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38AF968B9C0; Sun, 21 Aug 2022 04:37:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067019.outbound.protection.outlook.com [40.92.67.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED42968B83F for ; Sun, 21 Aug 2022 04:37:17 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PQfGgpZgYHRs0LOifEyryGFv3BlXFZr/OLjQOTuS9F/8gLyk8J5grMbUmtgd9JsXeZ1EBGDPodT8F4r4QrGydpXOXm0bcZV7gzvJRbCM+qF66SyhX0LGh8O3WuZK55fyfn5SGDRQvIMVjk/8w9Ufy1g+aL8OR2MvVjfNmlxghVvIIQ9CRoDXt4Of/4FxyEVrkNApXqfqktY8ItYC4GHvE5i01ToLuezmESgVI+2vXtQfP7IJU3lzLHSdcskioKJMm4EtyEpD+/P+xoh6A9O0w1URP0+g/yMK65OU/U1gty93VrSsgrZJUDMJq0eYTx1iOLYKJfkkuQvrIV42rqTtYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gmmETuc0pzGW9qFUtz26e8+chUBMSILcIsWG6dEUreE=; b=eaJQ3ZngGe5t5GkH4HzBls05xPUJ7Zfc9Bxu1Z2qRKOJ450G2zQf0Kq+vmvX7kvivs6k+0HkaqGfeDuUa3VxLf3lkW/GET/qPJzoDBAybnaq2rK4Q/Y4XNeeeI3e54CfC7SP0Av4YwSOA0q6kCqouHsxgudXjtKY+3s1p1o2LliXgdmcPiuWjP2mXYpWzV2pCHJK5/52frZ7QavEg/9NvZxsAwxjRVb1Xx4BAvaJ+UAJCvKJ9UlAZbYxfWRWLzizxOA+/WikMvIu6aVbAYF09BsboSPN88ZSc6BQVErBZZD5yrHB/Le6OB2rkTGFb/xZwWB+Di7qsJSYBCsHBPX/oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gmmETuc0pzGW9qFUtz26e8+chUBMSILcIsWG6dEUreE=; b=DxWlPo0rEj01Kb8ZqJ7Xv0o1RORUjCEjptMuj/0CUeE7gn48HexEF7cj0PzT0/Isn3A+FRf16tfK9TprHk1SD2VicdCU5OdWeO5TeDyfJ6T5wYWewIAayYREv12wnNalRBD08NKNvNDlxM8Zty9yaCGITsj8ZvjbR1kT5pf3psbxK0Vzid7eGzeVDAdGAhwd++chLquFeoW//PhLDG7g2L1cHMifZ0TDnRTLQjb8vdeOr9pP5js8WJ9BgxUQI+m96ogVpsCoynScvfjEjCP1j0CJ1Uqw22c8R1FQtVwm6kl3pUumY8Nw4tXE2Ob6Gt7yqn0aOa+CXN+TjotC4M6rVg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AM5PR0102MB2819.eurprd01.prod.exchangelabs.com (2603:10a6:206:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.21; Sun, 21 Aug 2022 01:37:09 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46%11]) with mapi id 15.20.5546.021; Sun, 21 Aug 2022 01:37:09 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Aug 2022 03:36:56 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [SUEJkvGjPQkPpequRs6BJOsFeu++uIT6] X-ClientProxiedBy: ZRAP278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::15) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220821013656.1345943-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a28ed6a8-1c7f-4b31-b5fd-08da8315a980 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOjPmV/Ff/svjf1oSkl2m09zRR4ou825nQhGhQYdju7sMh8Zddowsbing8O831/rsrCMriE9lrPPeFUe1OIzhws9vgGokid8UkA0nux0FvtFpw1ca5IaILj9G+m0EPLdf2Rd+KYzwytPGYjskfDngt1USOvXcklOZy29veGt4ce4YIK/kelqCrnVoQR4r+4Y/5kgTe/v2FPQ1N5Yb8NaBS1pPZAia7Fh8cVkJsGQ3E9jNPCVCYz4LqEBrnP0/6L2rb+HEWI+roFXJGnk34nuLEYthHdnKBe5peL1VZHUeEhsKSQp44gc9w/DmVT+mhIlkoiwRG7MvOmR9mItOx7L8ZaCVTFgJrbtVc5n+5gB+JFoSsnB/xSqNsD2OfAoQ/9524RDmwaHGCQEQ45OAsBcilDsVFEFRBiLq0SgZbHTvyc40QHIWVktFV0pe9W8KZQEQOaKbptUpX/7zafFtRKZMPI2vwuRbo50Lj2BFObTVVuEXD8hbIIpDGOJoHh1hmIFmykUN8MTY+Fdl7j1JPOnt4eGn/Y/jcJQqNLPGwV4MRXRwL4uwDjULYl4XAlGJyXyZCzlw9K1Gia6lS8NlrlU+rYRq/QkC5cymRNFDSdwtc1MVrFDTsVUUIGvVTHgN+V3GgOo7CXbsxDJGhNXJcoJlxM1UkhqmIXjPozzu1TgqMdFmAYT00KQ98UETaMaGi7m3mBHnBI8/DaO+PqQ6GWibSeaxHUSDGF6Y= X-MS-TrafficTypeDiagnostic: AM5PR0102MB2819:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lg2oNJDr1yU4psYBDPLBA4mUM5+jKPQwdUcBC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g/OnTl8/0xODMO0px7CeL/onb2fG5OUTT75lHkeEXqvVin3kp0OEoJCsJ6IFWg2I7Nmsg107SfTpcMd6QnBftyIf87zUV1ZXXcoyOfanGO/ATLw5W3nYMrLC8VvvnQQJqofR7YP/BzoEJzemn8oDwQOCA3GUtIaM2kVNgt11+6v+JHGtdjPGTXIsPPkj6sDhj6An000n+/M6nmHn4VZ0hWZfBJalF8XNDTk1gr9tpSoPk3DIXI9GIqgl9PCkHiKVlPVrlw9eGBMmvBZL0zjARGZlyQ6DNm3Gv99wnESGlzIjFtz2oYiisPovpXJKN18aZRdeZDAKRE43/FF1I0PdNt9Y9EP/y4td9q/xPtyr6UuQvXVXQYUj4Sf9I7+ZTAHvnR8Io+bZkYcuA02ivUXBtPm5x7lipbBpmkSBEiADhWAw5rQfjpmDmdwOJz415Yy5AnJscD6t0MiqbRIyYY3WGkCJLbfBYEHq/7DhUDjjNX9MdzWsMxNmwx/4gam/6ZnK41mI+4+BJ0dsVPXe6GZh7HjM+GDMZ/G974tigR4I5+XPxZaoG4xVtACziqeQWWNiBLyoZMECb6iGizoDj0yhHYQdtl9EW95ZyHeF7zJbfIquegb4KMhZw24hAgSaFM49Wfo5T866+9yR6ihTSD7FiRGbEP2hJWbCGceIJwUXFDidaSVXvFh8u4JLSxx7OCCFxv6Ea6FUtMpgChKYDJCiDgKc11eh+A4hrdotoxoeSzhK7Q0wEh/vnMW0OOUpDkiNRf0G5vJjm1+MV7d+T5MvKaa/qzwS8IZYXUcfuVXB/ZfCzMsx0e/syaCRNn9bsABD1Mui5bzzDVsSNpu40m3VL87DI0MdWDOBMiJxfIo6bKXzW++9IqbvFuEvaHYQMcic4BmfxYmWX9F7fvI9cs9NJfSHGejT/lzw9qJM8n7vag= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a28ed6a8-1c7f-4b31-b5fd-08da8315a980 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2022 01:37:09.0651 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0102MB2819 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/pngdec: Improve decoding text chunks 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ct2FZfNf1Nw/ By checking immediately whether the first allocation was successfull one can simplify the cleanup code in case of errors. Signed-off-by: Andreas Rheinhardt --- libavcodec/pngdec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 132ad40dc9..1d6ca7f4c3 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -551,12 +551,13 @@ static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse text_len = data_end - data; } - kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword); txt_utf8 = iso88591_to_utf8(text, text_len); if (compressed) av_bprint_finalize(&bp, NULL); - if (!(kw_utf8 && txt_utf8)) { - av_free(kw_utf8); + if (!txt_utf8) + return AVERROR(ENOMEM); + kw_utf8 = iso88591_to_utf8(keyword, keyword_end - keyword); + if (!kw_utf8) { av_free(txt_utf8); return AVERROR(ENOMEM); }