From patchwork Wed Jul 21 15:48:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Simpson X-Patchwork-Id: 28996 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp6446555pxb; Wed, 21 Jul 2021 08:48:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySyL+aOWi5ANlHr+V66M8HV9aHjRCy+/ncV4l0Ujce/yGZTDvBfg0oMz+CNcADNvyxiPvx X-Received: by 2002:a50:baa4:: with SMTP id x33mr29711500ede.259.1626882504228; Wed, 21 Jul 2021 08:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626882504; cv=none; d=google.com; s=arc-20160816; b=DF4FNb8smTdI7X72aQvmRYD0U2UDN0aHwmpS9KAn/ncKCpTU6yAsb1uVGaScibGZtL /NFTe+EX3UPL0jBWCkOjX041NFKuCEj8KFn1HQfjmiLMyCZOeeAvJv1PGD5o4j8ScXck GwLkx0ZONXjsIR3KxnZGc71/gSd24FjwxVRuX2oAU1EI5/1a22WotWkqxLvlHDvWz7l2 wYk4vpl0NMm+Vm052vfp/LO8ph+ihEzRGTBEDJcxpwsJuMEjVmZaoxVqxqqFSYAeDcG0 2JBOcwHEV9r6y2HcLtn7jdJDMfA1vtVaUQEYyhEyBkI1pMWDJ3HWbkSNKDBPfRHMbSW4 8xoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=G7XyeknZkYW5RmZPkK6EYCR0sYsPfS+dCl6azsADt+4=; b=hVqRdTfYOFNTVIZQfslAx5I91C7eeKnDwTwifK+nc9Vv/OfluYpMOA7grWsc6Alact /vcB5b03CYyKCh/ZahF5BUt3KfsrqMhdcb0e7wt6e7uFgHh1+ZkLLn9Bk/MiXVMKDRB/ GThUhgduz50zzURqyoXPqPoLEtPQ2VG5UV/n9S2Lcr8yWtoi58xTiCjQZz6enH3Ad/Z9 xCW6ojSnI6avZL1hsrj+2yobHhQEliY0d8zAtrG1gqxzbXg8yOix64f3/iMU8PWUiLG7 rksvWmUHyTjgyjsD8KXzAbrGHGUREX1Kkq3ULI1DgVqQqUe70IIiGaXJb4cz3Rmazz/T LfUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iboMHaTZ; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k5si28181208ejv.445.2021.07.21.08.48.23; Wed, 21 Jul 2021 08:48:24 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iboMHaTZ; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF87268A94E; Wed, 21 Jul 2021 18:48:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8DC7668A0E7 for ; Wed, 21 Jul 2021 18:48:13 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id v6so3848041lfp.6 for ; Wed, 21 Jul 2021 08:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=2iUJ0TfMpuKOUkgCb3PWRsP6eUj88mIc+ad5bh/Q7Dc=; b=iboMHaTZJemRJOSyo+234vZj78bBFVy7mBZIRb++PbltHevw/mFNL+FkBsTuDbawIi c/Vr91wwUjE5GNI1QSqtct2g928m5PXGXRWf1NCwZU8RaCdrPgABaST6T6S0znqfPdtN HG50SV5SBgs6YPXbHLeJCD7F3chKsN7BMuq2FlyqFAp24K0/6JZOeyL07lgXac32eFLa Zby2Z9V+b3ZVZou98Cm/w6C6E6W8FYjAY4arpwk2pG8d7qLfc9snuO3R1im1q1qNsb4h OidSbEHWGmZT99V0czStRPf2b0ksvb724GekIiH8R9K2xWXryA6yg0ASoSLH1Ok0Of07 idjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=2iUJ0TfMpuKOUkgCb3PWRsP6eUj88mIc+ad5bh/Q7Dc=; b=rlFx3f0f1+xywy3waKI9g7PRpwKBOIDvrPRidhSA6jjFJgrMYjiGltAmNNA0ztuzMs coNqQq2ZgSlQQE7KizpIVYFFWt7T18NV6FziE66RoQrFw5lvjuUNtWPYCLXsZJLVa2nm 7BPD7kxFAwWZjYDzpffF4ohcpvypR+RpjcyX2TuFg59WXk1KJhD/PfxEWj/LCyobrDu6 7bzmHNIr6V2xuJO/hwE9SmQvzQXFnF6mJNT0znjIq++q3agQHigBVES4ToNi72M7A/ox AFSPY817tdv3tslg9LWEFC/0UcWI740puGd2XvfMamWDTK0GtfDZqrZvTLBhLbFNMpiY brIQ== X-Gm-Message-State: AOAM5316UdkyZjh2NkGVt7EtBXpq+xCdqZ+SPpoFYyU4D4b5RdyejSv9 MlzNEmjG5ub19gsnw0rfPtj/8a3vlMKx0pWPiABaklkOZO4q8A== X-Received: by 2002:a19:ac45:: with SMTP id r5mr25864814lfc.484.1626882492858; Wed, 21 Jul 2021 08:48:12 -0700 (PDT) MIME-Version: 1.0 From: Shaun Simpson Date: Wed, 21 Jul 2021 16:48:02 +0100 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] Patch libavcodec/jpeg2000_parser: Fix skipping of JP2 info markers... 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tchY1nWR6HIu libavcodec/jpeg2000_parser: Fix skipping of JP2 info markers by correctly reading marker size. This fixes playback of some JPEG2000 files that fail with a frame not found error. When reading the JP2 info markers, the parser can be triggered into incorrectly calculating the number of bytes to skip of the next tag. This is error is buffer data dependant. This patch corrects this testing if the next marker is a info marker, and correcting the number of skipped bytes if it is. Please note that this is patch 2/2 PATCH 1/2 libavcodec/jpeg2000_parser: Fix parsing of tile-part header, and frames where the end of frame marker is at the end of the buffer I apologise for splitting the patches this way. Thank you, Shaun Simpson Subject: [PATCH 2/2] libavcodec/jpeg2000_parser: Fix skipping of JP2 info markers by correctly reading marker size. Signed-off-by: Shaun Simpson --- libavcodec/jpeg2000_parser.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c index b332a067e5..e16ca2174c 100644 --- a/libavcodec/jpeg2000_parser.c +++ b/libavcodec/jpeg2000_parser.c @@ -81,7 +81,7 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ { ParseContext *pc= &m->pc; int i; - uint32_t state; + uint32_t state, next_state; uint64_t state64; state= pc->state; state64 = pc->state64; @@ -142,7 +142,17 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ } else if (m->in_codestream && (state & 0xFFFF) == 0xFF90) { // Are we in tile part header? m->read_tp = 8; } else if (pc->frame_start_found && info_marker((state & 0xFFFF0000)>>16) && m->in_codestream) { - m->skip_bytes = (state & 0xFFFF) - 2; + // Calculate number of bytes to skip to get to end of the next marker. + m->skip_bytes = (state & 0xFFFF)-1; + + // If the next marker is an info marker, skip to the end of of the marker length. + if (i + m->skip_bytes + 1 < buf_size) { + next_state = (buf[i + m->skip_bytes] << 8) | buf[i + m->skip_bytes + 1]; + if (info_marker(next_state)) { + // Skip an additional 2 bytes to get to the end of the marker length. + m->skip_bytes += 2; + } + } } }