From patchwork Tue Mar 28 23:37:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 3158 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp853599vss; Tue, 28 Mar 2017 16:47:13 -0700 (PDT) X-Received: by 10.28.107.14 with SMTP id g14mr16923349wmc.106.1490744833248; Tue, 28 Mar 2017 16:47:13 -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 u131si5044896wmg.14.2017.03.28.16.47.12; Tue, 28 Mar 2017 16:47:13 -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=@gmail.com; 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=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1FB0A68997D; Wed, 29 Mar 2017 02:46:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E749687ECA for ; Wed, 29 Mar 2017 02:46:40 +0300 (EEST) Received: by mail-qt0-f196.google.com with SMTP id n37so10119qtb.3 for ; Tue, 28 Mar 2017 16:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=t7nBTcTi271bnjljvr8gvRVYRFl7dpB7HKDQAblzLuE=; b=AM6YdhasfnEhTR72hz+B+HUeWhTElpKkYJ6C5ko1qyhihQnP74LGq1iehSi+surnYL T81nki09wfKkzce0tJnqIrJ04neIAEHzEj8PYUHqs6+hte98XAgddj85pCXewfRnbazX Hps2j5WxF78aHZGxx83TAijrQXN9LnHoVZpUGYlG7nJ1BpP3Pp+t68ycqPKU2Zcjmawc 50+MfRt/0GoXLbe1nOKoDTZWp9okv8l5Ga/Mz72hN/5fBOt2taZqSjQ1Br68+YLai1lX 50Ig0Mwk1+8ifm3pf6Er3bkK5DDjMwkzQAI9Z1OvPZtsRxh+P04uAiMh05KusQli1GCI Y7pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=t7nBTcTi271bnjljvr8gvRVYRFl7dpB7HKDQAblzLuE=; b=ChfwOlpfNuoWAgakbVFECqPv1jGoJFwif9/2a3Ezb1+ThQXE6VhH1Dy17oonCaNjSe LimTB4hwD10SB6bbY9xp14GEEoym3CHTK6EY3fhb9Un1I+d1HHPwd6tlgZSw7l5YYOB7 Z6lQ1/2Z4elwmGETblzd6a6Zg75k/iIiQIgTJ1s2flJcqedGYmmF+9sYCl0ctKG6jUTw 5EEMEtw3hJbr3EoGiLi6Dn782sA21xflqfFHXePXc61b8rM9sfXACo8TRjw/7B+c5Doi swrOXXyK1jZLzOzXb9zcPfPiLcvoRACDS2bEdu95t6MiL1m25zLdAEnCG2s20y9+zm5R ySuw== X-Gm-Message-State: AFeK/H3AJR9H0lawvZnTzk0ZAPnPZFRJl2X1OiP0+Nk3ri1q6CXHxr0UOIvTj+pUx7xcXg== X-Received: by 10.237.34.59 with SMTP id n56mr29379189qtc.231.1490744278067; Tue, 28 Mar 2017 16:37:58 -0700 (PDT) Received: from Macintosh-7.home (pool-96-246-175-85.nycmny.fios.verizon.net. [96.246.175.85]) by smtp.gmail.com with ESMTPSA id 1sm3748596qtb.40.2017.03.28.16.37.57 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Mar 2017 16:37:57 -0700 (PDT) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Mar 2017 19:37:54 -0400 Message-Id: <1490744275-59294-1-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 Subject: [FFmpeg-devel] [PATCH 1/2] png: split header state and data state in two separate variables. 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 Cc: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes a reported (but false) race condition in tsan for fate-apng. --- libavcodec/pngdec.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index a4eb6cc..bbb9610 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -45,7 +45,7 @@ typedef struct PNGDecContext { ThreadFrame last_picture; ThreadFrame picture; - int state; + int state, pstate; int width, height; int cur_w, cur_h; int last_w, last_h; @@ -334,7 +334,7 @@ static void png_handle_row(PNGDecContext *s) } s->y++; if (s->y == s->cur_h) { - s->state |= PNG_ALLIMAGE; + s->pstate |= PNG_ALLIMAGE; if (s->filter_type == PNG_FILTER_TYPE_LOCO) { if (s->bit_depth == 16) { deloco_rgb16((uint16_t *)ptr, s->row_size / 2, @@ -369,7 +369,7 @@ static void png_handle_row(PNGDecContext *s) memset(s->last_row, 0, s->row_size); for (;;) { if (s->pass == NB_PASSES - 1) { - s->state |= PNG_ALLIMAGE; + s->pstate |= PNG_ALLIMAGE; goto the_end; } else { s->pass++; @@ -404,7 +404,7 @@ static int png_decode_idat(PNGDecContext *s, int length) return AVERROR_EXTERNAL; } if (s->zstream.avail_out == 0) { - if (!(s->state & PNG_ALLIMAGE)) { + if (!(s->pstate & PNG_ALLIMAGE)) { png_handle_row(s); } s->zstream.avail_out = s->crow_size; @@ -541,7 +541,7 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, if (length != 13) return AVERROR_INVALIDDATA; - if (s->state & PNG_IDAT) { + if (s->pstate & PNG_IDAT) { av_log(avctx, AV_LOG_ERROR, "IHDR after IDAT\n"); return AVERROR_INVALIDDATA; } @@ -585,7 +585,7 @@ error: static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s) { - if (s->state & PNG_IDAT) { + if (s->pstate & PNG_IDAT) { av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n"); return AVERROR_INVALIDDATA; } @@ -609,7 +609,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, av_log(avctx, AV_LOG_ERROR, "IDAT without IHDR\n"); return AVERROR_INVALIDDATA; } - if (!(s->state & PNG_IDAT)) { + if (!(s->pstate & PNG_IDAT)) { /* init image info */ avctx->width = s->width; avctx->height = s->height; @@ -690,11 +690,10 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, if ((ret = ff_thread_get_buffer(avctx, &s->previous_picture, AV_GET_BUFFER_FLAG_REF)) < 0) return ret; } - ff_thread_finish_setup(avctx); - p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; p->interlaced_frame = !!s->interlace_type; + ff_thread_finish_setup(avctx); /* compute the compressed row size */ if (!s->interlace_type) { @@ -734,7 +733,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, s->zstream.next_out = s->crow_buf; } - s->state |= PNG_IDAT; + s->pstate |= PNG_IDAT; /* set image to non-transparent bpp while decompressing */ if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) @@ -786,7 +785,7 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_INVALIDDATA; } - if (s->state & PNG_IDAT) { + if (s->pstate & PNG_IDAT) { av_log(avctx, AV_LOG_ERROR, "trns after IDAT\n"); return AVERROR_INVALIDDATA; } @@ -1122,13 +1121,13 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, } if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && length == 0) { - if (!(s->state & PNG_IDAT)) + if (!(s->pstate & PNG_IDAT)) return 0; else goto exit_loop; } av_log(avctx, AV_LOG_ERROR, "%d bytes left\n", length); - if ( s->state & PNG_ALLIMAGE + if ( s->pstate & PNG_ALLIMAGE && avctx->strict_std_compliance <= FF_COMPLIANCE_NORMAL) goto exit_loop; ret = AVERROR_INVALIDDATA; @@ -1231,9 +1230,9 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, break; } case MKTAG('I', 'E', 'N', 'D'): - if (!(s->state & PNG_ALLIMAGE)) + if (!(s->pstate & PNG_ALLIMAGE)) av_log(avctx, AV_LOG_ERROR, "IEND without all image\n"); - if (!(s->state & (PNG_ALLIMAGE|PNG_IDAT))) { + if (!(s->pstate & (PNG_ALLIMAGE|PNG_IDAT))) { ret = AVERROR_INVALIDDATA; goto fail; } @@ -1333,7 +1332,7 @@ static int decode_frame_png(AVCodecContext *avctx, return AVERROR_INVALIDDATA; } - s->y = s->state = s->has_trns = 0; + s->y = s->state = s->pstate = s->has_trns = 0; /* init the zlib */ s->zstream.zalloc = ff_png_zalloc; @@ -1400,14 +1399,14 @@ static int decode_frame_apng(AVCodecContext *avctx, goto end; } s->y = 0; - s->state &= ~(PNG_IDAT | PNG_ALLIMAGE); + s->pstate &= ~(PNG_IDAT | PNG_ALLIMAGE); bytestream2_init(&s->gb, avpkt->data, avpkt->size); if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) goto end; - if (!(s->state & PNG_ALLIMAGE)) + if (!(s->pstate & PNG_ALLIMAGE)) av_log(avctx, AV_LOG_WARNING, "Frame did not contain a complete image\n"); - if (!(s->state & (PNG_ALLIMAGE|PNG_IDAT))) { + if (!(s->pstate & (PNG_ALLIMAGE|PNG_IDAT))) { ret = AVERROR_INVALIDDATA; goto end; } @@ -1456,7 +1455,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette)); - pdst->state |= psrc->state & (PNG_IHDR | PNG_PLTE); + pdst->state |= psrc->state; ff_thread_release_buffer(dst, &pdst->last_picture); if (psrc->last_picture.f->data[0] &&