From patchwork Sat May 2 17:16:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19441 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 D2F7944BB45 for ; Sat, 2 May 2020 20:17:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B6CB268C8AB; Sat, 2 May 2020 20:17:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9409C68C888 for ; Sat, 2 May 2020 20:17:52 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id j1so15719846wrt.1 for ; Sat, 02 May 2020 10:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QBW2f5k7M5Lrj6M4biK0ZXaRVOSumE7bjJI/ICDs3zM=; b=JMXEOedxQrLUYHP4FSenzW97nAjIJ8RuAdY9/HUErthSuHI8fZ3rR3dUVS2hjoB+kY QY563f/k4v0YpvuT59/IybkD5Nzrw/xVDBwh3RcoPQilBVE4pcXUpyKN+VLJ90hB+DD5 9JO0Gu5mZqcr1GPBLvURgNJM8jqdZdZYiAAb+XuC4OB73/ZBIkJEYqhexoNQdWWA5ePk jg9btQHvpT7PBGC7KlYX+kw6qe6a0sCVeq8gRnLsOtogmglC3HhCB1QsM8z8ocHlAFIO HgXipJmcwpFZ/1w8OiQ176Gxj8WPO5t1HFoT4UTdLV5HfN05F9YvhcrbsaAaZiQZLAn+ rcKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QBW2f5k7M5Lrj6M4biK0ZXaRVOSumE7bjJI/ICDs3zM=; b=PWG5i5PZt1Ucu3TUzX9h7M0g1oaSp++7tyk3vmdfgR3gqQdLBcgOgSfndpsVdkNVYa gTI/G+udcFNvRKnJtjKnj64xNdWe/7cnC+oo7WcyTFfOqYcPsMnCMd8ZulEP2foaAPmV lFmSHCKrK/+Zl96olVjf5NVefN6BjW8GUZWzTuqeuVvlhgzhBftILHPfH5de4IrrWlt0 cljHh3IDlFkhe4JD6j4R30SDpTeMIOJ6R64AS+CRnEAB3wbp+4O/Qb0IJ+GyHrtQeM+o Y9oN9+mq0AllBPtJ6W7zUh8d1GBqysUx7LP+Hm/svc4Z49bMGKmjsd4kFejt5+LPs1yo Czwg== X-Gm-Message-State: AGi0PuamOsBlp1LG62K9QNu2MKRCm/l7nu11Avu3IcdkZjTukj2P18LZ 5W8+CGFwDSuEHSfL9rSyDlV+v/3E X-Google-Smtp-Source: APiQypLXDuQZ3GJk3wX2TI+a9gaKA0kIC63OGoS6k6LixMHdUBgtyGL8iFZrS91BjaxHEPc4kxKJNg== X-Received: by 2002:a05:6000:1242:: with SMTP id j2mr9770599wrx.274.1588439871727; Sat, 02 May 2020 10:17:51 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id u74sm5241524wmu.13.2020.05.02.10.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 10:17:51 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 May 2020 19:16:59 +0200 Message-Id: <20200502171700.28991-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200429222156.29129-1-andreas.rheinhardt@gmail.com> References: <20200429222156.29129-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/13] avformat/matroskaenc: Don't assert when writing huge files 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" EBML numbers are variable length numbers: Only seven bits of every byte are available to encode the number, the other bits encode the length of the number itself. So an eight byte EBML number can only encode numbers in the range 0..(2^56 - 1). And when using EBML numbers to encode the length of an EBML element, the EBML number corresponding to 2^56 - 1 is actually reserved to mean that the length of the corresponding element is unknown. And therefore put_ebml_length() asserted that the length it should represent is < 2^56 - 1. Yet there was nothing that actually guaranteed this to be true for the Segment (the main/root EBML element of a Matroska file that encompasses nearly the whole file). This commit changes this by checking in advance how big the length is and only updating the number if it is representable at all; if not, the unknown length element is not touched. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index dfc1563fc1..fd590597c9 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2542,9 +2542,13 @@ static int mkv_write_trailer(AVFormatContext *s) } after_cues: + /* Lengths greater than (1ULL << 56) - 1 can't be represented + * via an EBML number, so leave the unknown length field. */ + if (endpos - mkv->segment_offset < (1ULL << 56) - 1) { if ((ret64 = avio_seek(pb, mkv->segment_offset - 8, SEEK_SET)) < 0) return ret64; put_ebml_length(pb, endpos - mkv->segment_offset, 8); + } ret = mkv_write_seekhead(pb, mkv, 1, mkv->info.pos); if (ret < 0)