From patchwork Sun Oct 4 17:14:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 22725 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 035E3449E06 for ; Sun, 4 Oct 2020 20:22:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C97BB68AE7C; Sun, 4 Oct 2020 20:22:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9EC366880B1 for ; Sun, 4 Oct 2020 20:21:56 +0300 (EEST) Received: by mail-qt1-f195.google.com with SMTP id 19so7316252qtp.1 for ; Sun, 04 Oct 2020 10:21:56 -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:mime-version :content-transfer-encoding; bh=EmkDQ8uUykHL14sWi1RmLguUE2pT+J/Z+vES4iw5Y78=; b=GfmiFkt0yfWNfzYko0UOd+s44V7fqs7EypSpo6o2JVQh88IEGADbjBQpZc7CZVTY3q owmdSd2d665JO/b6JFcOPuaAraiQxqhsW3VE/te6uKTrOHxuwwvM6XTyEXDwodu7dJLu LNm2tqHZEbfRq1bY+2TNaaCQE87jQ8WLv/PYmDIM8TNN0oNGLWL0pm8mWR0vfkoMHxC5 j4DoqXoiy450I+POnPTiMnEXZYeh57vDbPzcKI3lySgzfxMbzJoCk1lFeZrMa0XyDwez gBVgMBXR5lsIGVEH3o5VGUFUJWZUQSDkoUpZiHERKX3K57NfXNVFra3HhXElqSN+dqkf AETQ== 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:mime-version :content-transfer-encoding; bh=EmkDQ8uUykHL14sWi1RmLguUE2pT+J/Z+vES4iw5Y78=; b=LbKJ4g0y08wEfaHL7Z9YXqqbS66eOnRfGy6A3fnRkF1QARoeUNBqdAuCWVwWdRT27S v9Jz0vFo5ikYN4zctQ4r0DbBe0CZb88sBBNyISooz160BZgr6vjPiAzpbI42Lr6hPlsn CucV4UFloeeljk/FdmgXZHSJd/EI9uqevGqiIXhE1xLX4vviyjpBzNA2yPitMJZsWxq7 jfQE4BCbdeLwegfwCnh16UcdkWXwHjIC1bfiHx5+irvdreD3zsUtbdrsQSxUAYu1z7VN ed0S+orqsqYGoOtXRt2exJjAYAa6QCeTzByrTy7uyILH2UJQk7PxW9OU8wOVlteP+z6V A+1A== X-Gm-Message-State: AOAM531AGrbAhvY1N7erL4s8ubx2AeW5co/4xH0icygL9D41lPAZ2gU1 hWeYNVQpP2qWI4PdBQL5qP6wmjYNqYE= X-Google-Smtp-Source: ABdhPJzxmgYg6GnGNpSJLjKt4ODlCTzI/qJ90ftBZKSmn/m03sVc1h60i76fejV2tGh+J9dxKU703A== X-Received: by 2002:ac8:4684:: with SMTP id g4mr1437548qto.140.1601831685857; Sun, 04 Oct 2020 10:14:45 -0700 (PDT) Received: from localhost.localdomain (c-71-232-27-28.hsd1.ma.comcast.net. [71.232.27.28]) by smtp.gmail.com with ESMTPSA id o2sm5661917qkk.42.2020.10.04.10.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Oct 2020 10:14:45 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Oct 2020 13:14:29 -0400 Message-Id: <20201004171429.174812-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mpegts: ensure seekback for small probesize 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman get_packet_size() may read upto PROBE_PACKET_MAX_BUF bytes, which may be larger than probesize. Signed-off-by: Andriy Gelman --- An alternative could be to make sure we don't read more than s->probesize bytes in get_packet_size(), but because this function is also called during resync (midstream) limiting the read bytes may not be the best option. libavformat/mpegts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 50d4d5e9bc..019b627d51 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -3054,7 +3054,7 @@ static int mpegts_read_header(AVFormatContext *s) s->internal->prefer_codec_framerate = 1; - if (ffio_ensure_seekback(pb, probesize) < 0) + if (ffio_ensure_seekback(pb, FFMAX(probesize, PROBE_PACKET_MAX_BUF)) < 0) av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n"); pos = avio_tell(pb);