From patchwork Tue Feb 13 10:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mattias Wadman X-Patchwork-Id: 46234 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9002:b0:19e:cdac:8cce with SMTP id d2csp1201503pzc; Tue, 13 Feb 2024 02:18:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUY+Uff5gvTFMQ6wLtwAuZ3QH30VXBvMzL2w2PYWoBK0UJfqyX+fpnV980BW/qqB1gNQ3zBOTTmB4x/4A+fqDYDkHiG8knJfeXBKg== X-Google-Smtp-Source: AGHT+IHY5hCXisS728D5rDmaYoEr2eUcEsu+hBcUqm8PQPZ/huDJ2fk99aNFZWSfXDJ8cxUKaYIV X-Received: by 2002:a17:906:f159:b0:a3c:f4e8:ac38 with SMTP id gw25-20020a170906f15900b00a3cf4e8ac38mr1090529ejb.9.1707819484731; Tue, 13 Feb 2024 02:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707819484; cv=none; d=google.com; s=arc-20160816; b=qD3A0egiVdfyHTlJSvr6fjEjNM10yoBIWphAPadRfOtzn9CKLT6gcP9eSx02w8BLtD uIo3UwShIBm2OdozAU7ez4NEwwqDUDiDTFpcTtwjbF8QzMQ9twZXQBIDgaiW+eHKSwdC 2ikrHEVswYuFqAxCeYbaCxk0khyazmk/9y6q014FrYjm5jFzBb4ngJJDJNsMklB3ibC9 Jv/MTgLMTgJhXg7g0oAG38r82yv9DNbSmtwP273JzrNV8blYuyhwzGDlFE4UdBgns32o vsViBmz0oqGJgsNlZoL8XIyRYWngZ49d8T+pQBH4lpjRgDDniXmmZa2N1/x983xBZwv7 Pjwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=34+s1hTcNxa6okqeU9DlD4p2bM5ScVBKxr7kW5OA8zU=; fh=+djYTvfGSa7tQSZZHYnwLRzVNailVQ48STLKLiUfqXg=; b=nBsg7efgiR1PrZYG99HO4JBVGL+7CVxRqot+YdjzRWBkgv3yiiZGp75eKciFIpJnaF RD5CdiQSLUI+R8LHNJjBp8+1XO0RpKZYZpH11zB+Pw6jIc0ZWRx0tP7PnXJNq0v4ohmY 9L5zr4NhixBJ+FcAfxLDAY2kjS3zJr5ai8gOsYhVYgjXOItRWz6/wj0W7hxrzb2wPLBl rXgO8vpTGsCj+xHEBp0kXDTwPkhJ0IPjNc+cxK9yn2GpeqVVmn0Joaz67egv/zPYU7ma MgoN3pbUBpnnZb6Ljs+oWhGg5UQVKzQJ+xGs0PN8WusGhkcu2AHhsWUufoIzqJXknCwM 1ojQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=iyRIzTbi; 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 X-Forwarded-Encrypted: i=1; AJvYcCVdhp2eMBZuV+UBYt2sCLO7nIv62/FzqP9wOFktlEuOy9EwZtmP1NCwGzM+Auz9MUAPCpPdrGnnMUWQfop2EjrjdUtE2zgBtALC+01j3ZPynWXH+t9KBGKRE7rLGgPbjuBmsAFr4lpKcTamh08ekKYoVGYPbhV+nLeYEylFCjk6N9Jg4Ts42mDDZ/jatvjBL6qQt5WjRsX8glhzZ0PT0l6pPH9hZJdtsAQ5AyYqWlA+RC6mLaPcYgDvsYK9HGUtB4GlEVM+8wChRBYAa58W7FQp5KdM+W/i/fTuTNg7Z2exc8Onk8w5TN/uBdC/rBIgpuHr1JaYE9bvbgwyAkfBP+h+UoPcKwx4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rxft0RI22vNX8czDeNuCMIlEXSM5QUbkxKfh3JjuDBFeUQwL9AampH9sfYnajGlr71UFk06BZFVhjdw6YxRKnYw7HGopi21jNrPg+Oke+EcH2EL3NTqgeKMInLyhopa1m5NgwqPUcC5w== Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id lf6-20020a170907174600b00a352247f161si1118636ejc.545.2024.02.13.02.18.04; Tue, 13 Feb 2024 02:18:04 -0800 (PST) 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=20230601 header.b=iyRIzTbi; 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 B6DF668D1EB; Tue, 13 Feb 2024 12:18:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 581D268D11C for ; Tue, 13 Feb 2024 12:17:55 +0200 (EET) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5600c43caddso5023777a12.2 for ; Tue, 13 Feb 2024 02:17:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707819474; x=1708424274; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RnqCBuDGheYfGPY0tDqxsK1dm7Dj0FW0M1hZsTaLDsU=; b=iyRIzTbibXWQxKL//kQirnXZJrq1Av7GnqmA3FMARzlQf7pEd8KUGo3hMNKrN3iJMO aU/8bjrijp+EeALDAw2adzlni5Ukp/f6uM5zeeLb9lHCEyoojIgf5dp2ZzJruMZvS5vv isIlzC0Gcu29gJWaGmVLSSmI8Fvl3JyiCl2cW6PmChrPBJG77ZVDsiFIpmVDbFMrs5qw clijBBaqtxDVijElN8GvqhDY4DYIFp5ARBYkut7+Pd5mm7T5ueZIsQiBGXMSrOtvYEUk ViPzxgD3oJg4SoqsXl4FqC3TOpXjJbko72vsnOo/3jWr4Sy0EVxp5IPwnie+VBjifgSu HT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707819474; x=1708424274; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RnqCBuDGheYfGPY0tDqxsK1dm7Dj0FW0M1hZsTaLDsU=; b=JAu9ZqAJlOW3WHN+OZyobI5WibpSsDz7jv8U/gNbz01aw7gcy/FCsSAjFBXs2NDM7Z kMzmPJ5Jd5njHAW8R4NmhVueGz2p/nEfGNSUsruTIHIL9WAFmIax3rqoN4VoloxG9ii6 wjO6rkh/fpJmLCf6cMEK0MLhT/lDljhnh+ExOT3XypYdwvq9jMMgzkT5ntN46b4rEzg7 3Q1H75oZesNzoxUpePZNffWnwn+Z7Uoet1Og89h3Q5OA3rHy7UvkklhG6FT3ymGtHHOy /3i2Y/Zc/zH9mQh4B6aesuWZGEQgRg1I/kBSHJyHHIYek5UE3kWoD1rOBJBnhPD+K4i+ QW6w== X-Gm-Message-State: AOJu0Yy7Zd5/19dCHOPcdWHarsf/l+pPvnnUhIrSu1+QeGMTncLU+/bA 3JsNfuOuicyZCzznrVeV2IQiByF2DKXl5dgAi4va6WEKrBIoWrn4MZ3Od1qZ X-Received: by 2002:a17:906:e297:b0:a3d:1994:d3b2 with SMTP id gg23-20020a170906e29700b00a3d1994d3b2mr234961ejb.74.1707819473882; Tue, 13 Feb 2024 02:17:53 -0800 (PST) Received: from localhost.localdomain ([80.169.186.251]) by smtp.gmail.com with ESMTPSA id ty5-20020a170907c70500b00a3c9c70fabesm1138836ejc.25.2024.02.13.02.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 02:17:53 -0800 (PST) From: Mattias Wadman To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Feb 2024 11:17:46 +0100 Message-ID: <20240213101746.56472-1-mattias.wadman@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/h2645_parse: Don't treat 0x000002 as a start code and truncate 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 Cc: Mattias Wadman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AF5v1tQf1QD/ According to ITU-T H.265 7.4.2.1 this byte sequence should not appear in a NAL unit but in practice in rare cases it seems it does, possibly due to buggy encoders. Other players like VLC and Quicktime seem to be fine with it. Currently when this sequence is found it is treated as if the next start code has been found and the NAL unit gets truncated. This change limits the code to only look for first start code 0x0000001 or first escape 0x000003. Sadly i can't share the original source file with the issue but the first 80 bytes of the NAL unit looks like this: │00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f│0123456789abcdef│ 0x00000│00 00 00 01 02 01 d0 bc 57 a1 b8 44 70 01 00 0b│........W..Dp...│ 0x00010│80 2e 00 c2 6c ec 3e b9 e3 03 fb 91 2e d2 43 cb│....l.>.......C.│ 0x00020│1d 2c 00 00 02 00 02 00 5c 93 72 6f 31 76 18 00│.,......\.ro1v..│ 0x00030│08 38 aa b1 4c 33 3f fd 08 cb 77 9b d4 3c db 02│.8..L3?...w..<..│ 0x00040│a2 04 73 15 75 de 3b c4 67 c0 8f ca ad 31 f1 99│..s.u.;.g....1..│ --- libavcodec/h2645_parse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 28db465059..9f66f079c2 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -40,8 +40,9 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length, nal->skipped_bytes = 0; #define STARTCODE_TEST \ - if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \ - if (src[i + 2] != 3 && src[i + 2] != 0) { \ + if (i + 2 < length && src[i + 1] == 0 && \ + (src[i + 2] == 3 || src[i + 2] == 1)) { \ + if (src[i + 2] == 1) { \ /* startcode, so we must be past the end */ \ length = i; \ } \