From patchwork Tue Mar 28 22:10:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 40902 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp2525169pzh; Tue, 28 Mar 2023 15:11:39 -0700 (PDT) X-Google-Smtp-Source: AKy350bzvmPUprxrliE4pRViA+/jWUXHZre//sL9YLgruRrVR97u6ogvbvPxw9UDgY/waN6wKhJJ X-Received: by 2002:a05:6402:151:b0:4fa:56dc:b6e6 with SMTP id s17-20020a056402015100b004fa56dcb6e6mr17056515edu.16.1680041498926; Tue, 28 Mar 2023 15:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680041498; cv=none; d=google.com; s=arc-20160816; b=zOlLxOIluPwL58fQxnNU4rfM3AxZUpsKTesCl4R0R8cO8Z6ABtLsDt2Wwjlec6mDLt 0Je4JZfGVokHug8WHebvU9Czo4ZeVTbSWwzErkSOnFq5mWN1Q43AhfshRu17QNsCgJZ1 bOjjY39N4V+hMX5Q2CV1oiJuqLVguY8DXDX/JANwsbDoiIgY5jvJmB4qGTBlmZUkg3Ns z9Li6uIXco2ubBULx+lxKHcpi7x+AVaIDxNAZs8GVzzLNiWvzl235gzhJt6gaOXz90ib pyhFfXx6XM6mIfUGrO8NGtZJXK5fYWUHBHFdg09UhfC29BpZ6sS/K/ZMZ/3JyyUZ1xmw nAYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=npEDPP7c7MbPa6sAPv0XhXHgA9mivLvGpB5db50vX/M=; b=IdRoYSQL8toOwbTJryMs6BE7jxUDijao34ay2ilqalrRAx2AQ/ymDQp5Wx5bdDF8Pw +V5ezyU54/nOC4cUsOyWMYNgOU7rKuuZUgAoL1draPE4KjlJ1bzzIkqtNTIOJrH9wpp6 u35YQDZEG0p3nOFz85XmEgxGxRtTV0COB8P1z3euQb/HYI2CM9t0kkYX+JHSLYZoSrjh H3zoNpPPqLvIlQcdfQIQF2EVVkundjSCYJV4psub78Eni9wjHv+lsrnEwtS+NHwAgVys 0RSgw4HC8Kp16uwY6bJrHcSbAJboqEgOLnM4EZ03KnpWrx5TVMpqoIgwgjsQJKCcbcNo PhPg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ca17-20020aa7cd71000000b004fb7ccf3b48si30149480edb.535.2023.03.28.15.11.14; Tue, 28 Mar 2023 15:11:38 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A0E968CCBB; Wed, 29 Mar 2023 01:11:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C3C968CB93 for ; Wed, 29 Mar 2023 01:11:05 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8891BE8B6C; Wed, 29 Mar 2023 00:10:48 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ufi37oRK18ow; Wed, 29 Mar 2023 00:10:45 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 28407E8334; Wed, 29 Mar 2023 00:10:45 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Mar 2023 00:10:32 +0200 Message-Id: <20230328221053.26905-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/assenc: avoid incorrect copy of null terminator 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jf+XihWLW+MX When writing a subtitle SSA/ASS subtitle file, the AVCodecParameters::extradata buffer is written directly to the output. In the case where the buffer is filled from a matroska source file produced by some older versions of Handbrake, this buffer ends with a null terminating character, which is then erroneously copied into the middle of the output file. The change here avoids this problem by treating it as a string rather than a raw buffer. This way it is agnostic as to whether the source buffer was null terminated or not. Fixes ticket #10203. Reported-by: Tim Angus Signed-off-by: Marton Balint --- libavformat/assenc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/assenc.c b/libavformat/assenc.c index 85a1e53371..6ecfb04517 100644 --- a/libavformat/assenc.c +++ b/libavformat/assenc.c @@ -70,8 +70,9 @@ static int write_header(AVFormatContext *s) ass->trailer = trailer; } + header_size = av_strnlen(par->extradata, header_size); avio_write(s->pb, par->extradata, header_size); - if (par->extradata[header_size - 1] != '\n') + if (header_size && par->extradata[header_size - 1] != '\n') avio_write(s->pb, "\r\n", 2); ass->ssa_mode = !strstr(par->extradata, "\n[V4+ Styles]"); if (!strstr(par->extradata, "\n[Events]"))