[FFmpeg-devel] lavf/spdifenc: Do not overwrite buffer when muxing TrueHD

Submitted by Carl Eugen Hoyos on Feb. 14, 2019, 7:18 p.m.

Details

Message ID CAB0OVGrH+h+dSOOkxoSExjOY=VdHcTindZ1V=2Bi3kv7QuOSeg@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Feb. 14, 2019, 7:18 p.m.
Hi!

Currently, when muxing TrueHD in spdif, the buffer is always overwritten.
Typical 64bit operating systems do not care, but this should definitely be
fixed before the new buffering model can get committed.

Please comment, Carl Eugen

Comments

Carl Eugen Hoyos March 20, 2019, 4:41 p.m.
2019-02-14 20:18 GMT+01:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Currently, when muxing TrueHD in spdif, the buffer is always overwritten.

Patch applied, this should be backported imo.

Carl Eugen

Patch hide | download patch | download mbox

From 3858971376f97241d29d4f7d3b261009af3c87a9 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Thu, 14 Feb 2019 20:16:18 +0100
Subject: [PATCH] lavf/spdifenc: Do not overwrite buffer when muxing TrueHD.

Fixes ticket #7733.
---
 libavformat/spdifenc.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 9514ff8..4307942 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -422,8 +422,13 @@  static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
 
     memcpy(&ctx->hd_buf[ctx->hd_buf_count * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + mat_code_length],
            pkt->data, pkt->size);
-    memset(&ctx->hd_buf[ctx->hd_buf_count * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + mat_code_length + pkt->size],
-           0, TRUEHD_FRAME_OFFSET - pkt->size - mat_code_length);
+    if (ctx->hd_buf_count < 23) {
+        memset(&ctx->hd_buf[ctx->hd_buf_count * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + mat_code_length + pkt->size],
+               0, TRUEHD_FRAME_OFFSET - pkt->size - mat_code_length);
+    } else {
+        size_t padding = MAT_FRAME_SIZE - (ctx->hd_buf_count * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + pkt->size);
+        memset(&ctx->hd_buf[MAT_FRAME_SIZE - padding], 0, padding);
+    }
 
     if (++ctx->hd_buf_count < 24){
         ctx->pkt_offset = 0;
-- 
1.7.10.4