From patchwork Wed Jan 18 14:31:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Angus X-Patchwork-Id: 40075 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp140016pzj; Wed, 18 Jan 2023 06:31:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXtMt90jVUN1E5rRRzq9HqJem2VOA8pBh+buqpCBlwlte03LH0WdhGnTvSpwIuykkoNT+5FE X-Received: by 2002:a05:6402:2419:b0:49d:2a42:b8c8 with SMTP id t25-20020a056402241900b0049d2a42b8c8mr8251336eda.26.1674052317874; Wed, 18 Jan 2023 06:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674052317; cv=none; d=google.com; s=arc-20160816; b=isvwhrGhIRsLfIaAZIuGSrlh83YfHYadnP9orv4Gxor4fWcfwezyyguZO8VGDu3iQS Dt5UINw6PJmSsvAMRBHjESCH5Nr335I+Fdwx+oPbFIAQMO6Se7GU/oGkwkcTl3S+MHbf uZY/ZxqXKdby3CYxxsEQ0aTkhrUxszwNRR3SAu9O8fqSkGpUc25dKcpSanRUiZJHtZ5d fXtlDQqPFL4vmj7+Fw0F1Fde5DCnIFW37mFB53W1DZ/RCh+++ZUTGtOMVh89H5/Y7H9j 2s+eHthzExedXlymNhJlm64Abw/xkpVqatpXbP/jHG6eALvRHCLDFmECY6hGJjxmqAnt c6Kw== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=tRRQ+wRSW5yqAtswEj8mPguTRXStJshKFrk/PHFUcFk=; b=C0Jn6KwpRcEKxna/X3dubMvSWwGCVm5TEsRLS9132sPoTU8vuyjrCUrs8lq5dDnb/O 5Road/auY4tsh09kAudr4+8y07co8RyS2mi0SmMcOUmX3iLL6k9ljuj5gdLx+gU3LbCm /sMBxgu0ii0ZKYN83qCRlDetmMOxpHvSdu5UyP3fh4EVkIugaFnSllwcgxqhwpGskMUR uAb2PIT8Z0Qtos0GOVdYqUFdX5pT5yNDyElAVkKFsah79GxHt6HRzCP5t3A5JKR0eCfl /cbYaJAYlfQbTeL+wH2DJkp+NEC5OvU+xVlkipq//D2offox2NxPujXQObHyWVoYN98l p2Bw== 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 ww2-20020a170907084200b007c0db556798si39628051ejb.994.2023.01.18.06.31.57; Wed, 18 Jan 2023 06:31:57 -0800 (PST) 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 54B4468B177; Wed, 18 Jan 2023 16:31:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailrelay.ngus.net (mailrelay.ngus.net [109.237.26.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51E2B68B435 for ; Wed, 18 Jan 2023 16:31:40 +0200 (EET) Received: from cpc102338-sgyl38-2-0-cust655.18-2.cable.virginm.net ([77.102.34.144] helo=zebop) by mailrelay.ngus.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1pI9TX-00B9BM-NT for ffmpeg-devel@ffmpeg.org; Wed, 18 Jan 2023 14:31:39 +0000 Received: from [192.168.101.3] (helo=localhost.localdomain) by zebop with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pI9TW-00Emf6-6C; Wed, 18 Jan 2023 14:31:39 +0000 From: Tim Angus To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Jan 2023 14:31:13 +0000 Message-Id: <20230118143113.324703-2-tim@ngus.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230118143113.324703-1-tim@ngus.net> References: <20230118143113.324703-1-tim@ngus.net> MIME-Version: 1.0 X-Spam-Score: -2.9 (--) Subject: [FFmpeg-devel] [PATCH] avformat/assenc: fix 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: Tim Angus Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9+pFhENTWo3L When writing a subtitle SSA/ASS subtitle file, the AVCodecParameters::extradata buffer is written directly to the output, potentially including a null terminating character, which is sometimes present. The result is the output having a null character in the middle; this is addressed here by avoiding copying it. Signed-off-by: Tim Angus --- libavformat/assenc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/assenc.c b/libavformat/assenc.c index 1600f0a02b..5e74b84575 100644 --- a/libavformat/assenc.c +++ b/libavformat/assenc.c @@ -69,6 +69,11 @@ static int write_header(AVFormatContext *s) ass->trailer = trailer; } + /* extradata may or may not be null terminated; in the case where + * it is, avoid copying a null into the middle of the buffer */ + while (header_size > 0 && par->extradata[header_size - 1] == '\0') + header_size--; + avio_write(s->pb, par->extradata, header_size); if (par->extradata[header_size - 1] != '\n') avio_write(s->pb, "\r\n", 2);