From patchwork Sat Feb 2 19:34:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11958 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 7B33C446953 for ; Sat, 2 Feb 2019 21:49:28 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6620868A4F7; Sat, 2 Feb 2019 21:49:28 +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 F2C2668A3AD for ; Sat, 2 Feb 2019 21:49:21 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id m22so9506347wml.3 for ; Sat, 02 Feb 2019 11:49:21 -0800 (PST) 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=tE3mPdlp3Y0gaRZXKYtzTi835tOSv18I0Cu3VDBlR8c=; b=YkMp6Sle7WRiOOBSIfICtTVjVjsm5Soe060CUOwxYxT3ani4R1OGvBzpUBoN8N38Nd vc0YxngQL3Je08ojuZ0L9/2BUxkyheh75Mu6aP7dzBJezrahvRIeDoqpd2+azlAhnoT5 m53WdLWeXCv9NuVY9Jt4pGtmvi8I24yaR0uyzaykL1ahra1LIDzTHMGmAZVieMkQlnix McWXqzO0JPZpZCx2fZWdWavbZ8hUfZcGoo+550enYxtYoHfpMuk9JWGWrtQyImCFdTdI /x8FYZKdu/CBI94TcczlsWOwjayth+qh+sT+TwSVpB5xDJ/qBW6y/YgmvGrXOlmfL0c3 aE+Q== 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=tE3mPdlp3Y0gaRZXKYtzTi835tOSv18I0Cu3VDBlR8c=; b=C7Ej1j6KfPnyTGU/nyjyuoEkGTi9UWxmg6pcWp9nDBxlc6LuTTNIncSnaUW1jf9ePu idE8eY1yO8Cnsee6w+4cXBiSHWO+2UV27vzU/wpp8dEoCbWpsorR/xF3myuijAtI7Nyu 88ZxJCO5Msa5h5b4rt1uue+w2UvwRQvMEG/qAW5YQ100RpfYdDU2ujVHcETXBeAGL7TX LhN7Yseh4zusN7zsaIRgLGr+y54h2y6hfBXTimDHG0qCojYHwALV1wbJ6g64zdV9Davl CEH0RHbeaMqsrhNE9jNQUbo93Cftb7KMBosVXOHePCFkO1lcMXldstaAmbaNMqAqAHSy WalA== X-Gm-Message-State: AHQUAub/XPgrJ/nkDKKvtsaIH1ceDF8b9EULHDK84HVnxJRubPm0kMeY rQD4AnZnIXJRh8UpD6xEzGHtbKRl X-Google-Smtp-Source: AHgI3Ia6Ngo6T7HKLTMs+PNP5RiLdXKte7oYdiph/JumKOBLK+yz/rl3ryG+uikecxzeEk3gXUtzgA== X-Received: by 2002:a1c:dc86:: with SMTP id t128mr7655890wmg.42.1549136624208; Sat, 02 Feb 2019 11:43:44 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id z206sm9137622wmc.18.2019.02.02.11.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 11:43:43 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Feb 2019 20:34:12 +0100 Message-Id: <20190202193412.572-3-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190202193412.572-1-andreas.rheinhardt@googlemail.com> References: <20190202193412.572-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] 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 DivX user_data section, instead it treated the first "p\0" after the start of a user_data section as end of a DivX 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 DivX user_data unit is at the end of the extradata. Both of these flaws have been fixed. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4_unpack_bframes_bsf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index 1daf133ce5..20d3e39c00 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -41,10 +41,13 @@ 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') { - *pos_p = pos + i - buf; - break; + if (!memcmp(pos, "DivX", 4)) { + for (int i = 4; 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) {