[FFmpeg-devel] lavc/truehd_core: Initialize the last bytes of the output buffer

Submitted by Carl Eugen Hoyos on Feb. 14, 2019, 9:44 p.m.

Details

Message ID CAB0OVGpYoUvX0feWu-x5nZwcQzAank2+Z2gz7pSSqYu=FaXVPA@mail.gmail.com
State New
Headers show

Commit Message

Carl Eugen Hoyos Feb. 14, 2019, 9:44 p.m.
2019-02-14 22:08 GMT+01:00, James Almer <jamrial@gmail.com>:
> On 2/14/2019 5:59 PM, Carl Eugen Hoyos wrote:
>> 2019-02-12 12:58 GMT+01:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>>> 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 <ceffmpeg@gmail.com>
>> 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

Patch hide | download patch | download mbox

From 18ac7557e5d2734c2be396dcfe25ea7cfec407a7 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
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