From patchwork Wed Jan 13 12:34:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Idan Freiberg X-Patchwork-Id: 24936 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 D2DBD4490C3 for ; Wed, 13 Jan 2021 14:35:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A1C3687F87; Wed, 13 Jan 2021 14:35:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D99068049C for ; Wed, 13 Jan 2021 14:35:09 +0200 (EET) Received: by mail-ed1-f43.google.com with SMTP id p22so1696954edu.11 for ; Wed, 13 Jan 2021 04:35:09 -0800 (PST) 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=P+ZUo6VNX3bu7MWRvlhDlpDNJnJdYPcrIhaAvfZ1aiA=; b=R5lhUgtXyVa2ECesPYCSFo68x5wHGwh5C+1IFmd0NWqgkY0M2CBJ2IeHlmRkTxOdvU XSWS7qnalqOkDFbqXgVsxJnBBHfb6ne4RE+pVi5QbGnvdoVd7+cf8FYwygLHGVdqHkZ2 C7IpepXrojIUGr4o76J97FAgyPjg8oOmfClSnm2ETcoY+IEDTNduEOxVNIqI5Dip340o ufNXF+dS4xtUZDJlNMN1TDOrpS1tkMZBTrWFNbbBrCrdkYl/42acy7+EniFT4EB++4O1 9phLCq3XkNwoQ0/9DdPujSIJ/LXoEKGnofX7avuEABUuJqqVWY0+rgOgZ445Fm7/Szba 6HqQ== 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=P+ZUo6VNX3bu7MWRvlhDlpDNJnJdYPcrIhaAvfZ1aiA=; b=twuTdeF0Ua0rBY+wpTxl028Ek4SHVNpfpjzA3UPznBec96h7ddhJwcKx2mlujXX3kC ORYoOD9KyB00DwAI6rRytgRzf/q9lgz+fUtKnCtEoW9TL3ZO+5IMYsTr13fgS314cavI IL+GaOhyRA8D1SH9ryeShmSSYEMNBXc84086SUTZ3944aHF9UpqJoPbtaw6FKp+t4YKL 1EG6jsW+vs0fqYmijlpLWLRWMHtIU7VAuNEibdOxuRrJuOy2n1kcGBHR5XC6PvSHygpz 4RBvcFs4mehSIiKUMih1ZBRa9yjPpAL95hox9Y14FydmrhKftPN5JLjDMDiWtrGsAtRh lwVQ== X-Gm-Message-State: AOAM530XYDR9XV5FEXcC2iKUkdzj6/BN1r5JkYCrhGe3hZBZMVT46rbY pWIK7Mf1t1d6hjOnOnEyzFQ7Kym1j56T6Q== X-Google-Smtp-Source: ABdhPJz2t2/KNBg786kqhZD0yW0oh+pdOhSUWpIvBFRuAZXSpJl6SeRQLh6ngr9eE3w9IkneUrN3hQ== X-Received: by 2002:aa7:dcc9:: with SMTP id w9mr1524458edu.22.1610541308461; Wed, 13 Jan 2021 04:35:08 -0800 (PST) Received: from localhost.localdomain (IGLD-84-229-167-243.inter.net.il. [84.229.167.243]) by smtp.gmail.com with ESMTPSA id b17sm665089eju.76.2021.01.13.04.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:35:08 -0800 (PST) From: Idan Freiberg X-Google-Original-From: Idan Freiberg To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Jan 2021 14:34:54 +0200 Message-Id: <20210113123454.27617-1-idan@tokagroup.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/dhav: Fix incorrect non-DHAV chunk skipping logic 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: Idan Freiberg Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" DAV files may contain a variable length padding in between chunks filled with 0xff bytes. The current skipping logic is incorrect as it may skip over DHAV chunks not appearing sequentially in the file. We now look for the 'DHAV' tag using a byte-by-byte search in order to handle such situations. Also the dhav->last_good_pos field will not be updated while skipping unrecognized data. --- libavformat/dhav.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 00e0d8476e..6a6c235e65 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -173,18 +173,9 @@ static int read_chunk(AVFormatContext *s) if (avio_feof(s->pb)) return AVERROR_EOF; - if (avio_rl32(s->pb) != MKTAG('D','H','A','V') && dhav->last_good_pos < INT64_MAX - 0x8000) { - dhav->last_good_pos += 0x8000; - avio_seek(s->pb, dhav->last_good_pos, SEEK_SET); - - while (avio_rl32(s->pb) != MKTAG('D','H','A','V')) { - if (avio_feof(s->pb) || dhav->last_good_pos >= INT64_MAX - 0x8000) - return AVERROR_EOF; - dhav->last_good_pos += 0x8000; - ret = avio_skip(s->pb, 0x8000 - 4); - if (ret < 0) - return ret; - } + while (avio_r8(s->pb) != 'D' || avio_r8(s->pb) != 'H' || avio_r8(s->pb) != 'A' || avio_r8(s->pb) != 'V') { + if (avio_feof(s->pb)) + return AVERROR_EOF; } start = avio_tell(s->pb) - 4;