From patchwork Thu Feb 14 21:44:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 12076 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7C10E448423 for ; Thu, 14 Feb 2019 23:44:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 690EA68A70F; Thu, 14 Feb 2019 23:44:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f194.google.com (mail-it1-f194.google.com [209.85.166.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D70368A276 for ; Thu, 14 Feb 2019 23:44:27 +0200 (EET) Received: by mail-it1-f194.google.com with SMTP id i2so18273758ite.5 for ; Thu, 14 Feb 2019 13:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=nnpfpHmb82ZZpnBV+pTx49Baq/hWRL/07G9YqdIYnv8=; b=pyqa3G1imZRof9XC3FReGQjnxdcdILZ/CtGLYSpEER4oyeIKpeLtQ065jlRCD2z4Bb OxreMxAAK1Ak3VrksZkxOElLArjuW6LWiEX+1LwW5Xi2EgKIGY4CWG9XeJF4sLrgrbrP yKMh4oWAKff6bwa01GVRciFndXn4FeKJn/w4l7rUT+cKWBfgYp1UhzF9qc52g8Bl0AFL tAp6rm+zcJfizs6e9sbrkKUTrETaphYE+ktKfoIRZSVw53SctzISUFKdcukkQ7fePhXl kp/CeRR2wMHut+Ujh0UiKZKJXju3aMEFCVp7I+n+gFq+gY6mQrLkuma1PUqoTCfSfLDm PSKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=nnpfpHmb82ZZpnBV+pTx49Baq/hWRL/07G9YqdIYnv8=; b=DFsVhkWVFiZmdhCxEChes649Jsk/vo3EzzhIBBh+B5T2SHkDsWgCplRdb6Ipj/C7YI 2mo9voAGlkDvAKVpbEqjbif0fOWUTWCnNj5GQD4sk2o8z3LjoeqLyc7dONRfqrwvAoyi xRRPRcBNZ2msr5jGmkZMN9A4Z81vWz+JP+C4XkUfSVuYFafxOa4ZBF57fVQc1EcRTkEp C335xCbUmiaESWfHge9aB/f8M5uIWPxTPYGhXDwb59ZxJTqqyhxiHIS+tcHKdxNa8jcR o0GwJaV8UYQygggSA56o/G8DCNtf06aJH9T25uxiX5a3scM9JZ/SA5uDY4YnkFa3eJ16 Q9JQ== X-Gm-Message-State: AHQUAuZhU1tR8goU4xSMUDHJm87EKb4b/UHJxpBLBp6X4h9d7cB2gNYm 6ZpRnyVqJUd5/Hb085gcD0/1JD2k65M8ewUUY+pjQw== X-Google-Smtp-Source: AHgI3IYFACSOFbLlwIelq4fQNSnJzpbRRZ4i49pWnPfpix6Q2o9v3G2wrNIiRJkCNfmnRoRz8MqQuuBhKQ3h5I4olsk= X-Received: by 2002:a5e:9707:: with SMTP id w7mr4137303ioj.49.1550180665570; Thu, 14 Feb 2019 13:44:25 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:940e:0:0:0:0:0 with HTTP; Thu, 14 Feb 2019 13:44:24 -0800 (PST) In-Reply-To: <707e8fcf-f06a-14ff-dab5-51b6bb5bc45d@gmail.com> References: <707e8fcf-f06a-14ff-dab5-51b6bb5bc45d@gmail.com> From: Carl Eugen Hoyos Date: Thu, 14 Feb 2019 22:44:24 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavc/truehd_core: Initialize the last bytes of the output buffer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2019-02-14 22:08 GMT+01:00, James Almer : > On 2/14/2019 5:59 PM, Carl Eugen Hoyos wrote: >> 2019-02-12 12:58 GMT+01:00, Carl Eugen Hoyos : >>> Hi! >>> >>> The output of truehd_core is currently undeterministic, the last bytes >>> are uninitialized, valgrind protests if less than 8 bytes are >>> initialized. >>> I believe attached patch is simpler than calculating the necessary >>> write size at the bottom of the function. >> New patch attached. >> >> Please comment, Carl Eugen >> >> >> 0001-lavc-truehd_core-Initialize-the-last-bytes-of-the-ou.patch >> >> From f3e4231af54b7a7664e1a2224cc1223be683f93c Mon Sep 17 00:00:00 2001 >> From: Carl Eugen Hoyos >> Date: Thu, 14 Feb 2019 21:57:48 +0100 >> Subject: [PATCH] lavc/truehd_core: Initialize the last bytes of the output >> buffer. >> >> Avoids undeterministic output. >> --- >> libavcodec/truehd_core_bsf.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c >> index be021af..4760872 100644 >> --- a/libavcodec/truehd_core_bsf.c >> +++ b/libavcodec/truehd_core_bsf.c >> @@ -117,6 +117,8 @@ static int truehd_core_filter(AVBSFContext *ctx, >> AVPacket *out) >> out->size -= reduce * 2; >> parity_nibble ^= out->size / 2; >> >> + if (out_size > 8) >> + AV_ZERO64(out->data + out_size - 8); > > AV_ZERO# may use mmx instructions. It should be safe if no float ops are > going to be used after it, otherwise an emms_c() will be needed and the > performance hit may remove any gain you get from not using memset(). New patch with AV_WN64() attached. Thank you, Carl Eugen From 18ac7557e5d2734c2be396dcfe25ea7cfec407a7 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Thu, 14 Feb 2019 22:43:10 +0100 Subject: [PATCH] lavc/truehd_core: Initialize the last bytes of the output buffer. Avoids undeterministic output. --- libavcodec/truehd_core_bsf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index be021af..dd40e1e 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -117,6 +117,8 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) out->size -= reduce * 2; parity_nibble ^= out->size / 2; + if (out_size > 8) + AV_WN64(out->data + out_size - 8, 0); if (have_header) { memcpy(out->data + 4, in->data + 4, 28); out->data[16 + 4] = (out->data[16 + 4] & 0x0f) | (FFMIN(s->hdr.num_substreams, 3) << 4); -- 1.7.10.4