From patchwork Mon Mar 11 11:36:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12289 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 7C5F6448FA0 for ; Mon, 11 Mar 2019 13:36:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64DF0688277; Mon, 11 Mar 2019 13:36:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 280916807D3 for ; Mon, 11 Mar 2019 13:36:28 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id e74so4072200wmg.3 for ; Mon, 11 Mar 2019 04:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=djTaUJNtGfgFeUaXoJpHaye3dXOWxDtTRDLe+1oO4NI=; b=B/Lc9v3SPOYPDjJo9kaLTNsK9K/er7/4NdNQWxcYkwwUDWsBD1T9EglIN7ZT1eDDnM 2Q2Ewc+MyN1OIeeLoODKUTQOwYYvA2s1zZpN/TdRoqv74R86vpt7FytI3TFHHR1SA6Sv WSeOoXvsyWl9t3acwgnZ83cX2NfwyBcKK3kLgnejERWSUK0DjuTw6uOx6GBXBnFzB2rN O0oXCTDeseed97148gJ8ial2ddqoj4hdGK66yPnubHlURnWBnbhnxW7ZGduugupZcgwr xXR31fhsCnPEpGcvnCHjG/STfW2oi7aIzmXonlcg2shNGHepzZzkEW0/txsLh6VqcVlX e14w== 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=djTaUJNtGfgFeUaXoJpHaye3dXOWxDtTRDLe+1oO4NI=; b=BEbprZFmYmTiyxaR/d1LyK+rkzOEngW7qm57HmgPubM3Q4cgMpWBVIzx4VruyclUh2 ZY/0/yMTKLcMI/VVtdJ6p572KAwoCbsWUAHPNxR8xUhesd7h/cyJ3/ngrh3p+SrjEX7W 1JQuxJFUbR01uFjDsvF1LKgz9GZIwMLhw+m6iXw2y6/6nVicUtsIWAWQapfVzwLvIsv6 iTMEtW0kkDQ+miVkGZdJtxmuYdBTLnZdGgQc1eTxl8c+ubzF/PioFwVHP9y8mCWW6Jq6 /ReDJNKlWnCMaPAAOkr1fTKM/pwc2njBEqqmOzPZl16ihQmOhMLuRlgb+QrOjDOp/ToU 7OxQ== X-Gm-Message-State: APjAAAVQiq+ADcnUaSPOxNypLj7suOdORqHTvTKyhRxzrIzyj6+t8lfT JOejA9T6cwHz1EWoZ6A1fNzXeDYMXuw= X-Google-Smtp-Source: APXvYqxT7m01OrWmLPuX/N9k59RT7laW1CidwsWbP/jtopsa/4/Qc76uNv79LGkz1qCf1zklYHjZTg== X-Received: by 2002:a1c:5f89:: with SMTP id t131mr17922840wmb.46.1552304187340; Mon, 11 Mar 2019 04:36:27 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id c21sm7099601wre.35.2019.03.11.04.36.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 04:36:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Mar 2019 12:36:08 +0100 Message-Id: <20190311113608.4140-1-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190204184325.GW3501@michaelspb> References: <20190204184325.GW3501@michaelspb> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/mpeg4_unpack_bframes_bsf: Improve DivX userdata check 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" The earlier version didn't really check that the 'p' of a "p\0" is actually part of a user_data section, instead it treated the first "p\0" after the start of a user_data section as end of a user_data section if it is close enough to the beginning of the user_data section; it actually needn't be part of a user_data section at all. Furthermore, the code worked under the assumption that there is a 0x00 after the 'p' although this might not be true for extradata if the user_data unit is at the end of the extradata. Both of these flaws have been fixed. Signed-off-by: Andreas Rheinhardt --- The earlier version was inspired by the check for packed bitstreams in decode_user_data() in mpeg4videodec.c where the "DivX" is mandatory, too. Note that this new version relies on there being no binary zero inside the user data. libavcodec/mpeg4_unpack_bframes_bsf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index 1daf133ce5..37bb0b20e3 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -41,11 +41,12 @@ static void scan_buffer(const uint8_t *buf, int buf_size, if (startcode == USER_DATA_STARTCODE && pos_p) { /* check if the (DivX) userdata string ends with 'p' (packed) */ - for (int i = 0; i < 255 && pos + i + 1 < end; i++) { - if (pos[i] == 'p' && pos[i + 1] == '\0') { + for (int i = 0; i < 255 && pos + i < end; i++) { + if (pos[i] == 'p' && (pos + i + 1 == end || pos[i + 1] == '\0')) { *pos_p = pos + i - buf; break; - } + } else if (pos[i] == 0) + break; } } else if (startcode == VOP_STARTCODE && nb_vop) { *nb_vop += 1;