From patchwork Fri May 6 13:57:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 35618 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp1680643pzb; Fri, 6 May 2022 06:58:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtpnrj4ZydyFRUDufGab9BYZvvSNhnxxjOWGUPpZpipIStXdjjkR7ZRFf5K5ztktY6DraK X-Received: by 2002:a17:907:16a8:b0:6f3:e9fc:29e7 with SMTP id hc40-20020a17090716a800b006f3e9fc29e7mr3146876ejc.428.1651845489495; Fri, 06 May 2022 06:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651845489; cv=none; d=google.com; s=arc-20160816; b=XF+mVdL9jYHqOVeYauMXHws7XOZJ2GtLRKkjqJ5an25dTiRPAUjZN0X64PhUGhX/+a ToOvfUzZ4fPT8XPoJTISvq0hXOoZ2/pVKkG14TCVeRok2j4QLEP01ZPTt8kuF6yLrMIL UlHa7HAcSIEgf+FyHKX8y11hLtQ4X5XctMIuD8NAVjYRKnij2KN433Qpf3xcHawXvk0/ JnSMZ7Io8qgyA8S6d+Nqq6xCVWpqe9+5b7nK15kOKjDAo7ErJdb+IAug4ejp15e5my/K eSYxozOGY8RVXLY8BukKYgJOn4QjNW8jyCivE8dzceM+0aNcciTPByl1CeDBgezEtgQk j1cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=uRTsnHykbZm3ay52d3anA6E8f1JzK42rkLKvdu7T++c=; b=Xs4XIpoaMYoF2hNHZzU3isTI1XrBCUy0o0fHyFK0nH424oEH0UPWTY3iOrBBXQKHFs /BMTmgeEMsCM+cff6L2GXajXqMVE8vNIP7zQN8hPvHJvECVdCyOCCNuLtJR9Pq83HacF QdR4XiGUCueJTWukPvnePp/yeXdMhHySX3T5GW+YgW3mmaPI0ENBCz6GIwEaEUUUNyHj ZrmvQHH0RxTG65N1HXHe770j5T3YOT+z8ujQ++fL5RYY5rvAWfpGinXGiD6fsvc35zuF rFhsBPGdlZ8P2s2ZVwIGHxKcr01R9wz+Wy1A7dHUfDRTOeN20Sxp6dYYLn5tC77OJC+K UHRQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g1-20020a17090670c100b006e80a81a548si4640745ejk.832.2022.05.06.06.58.08; Fri, 06 May 2022 06:58:09 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BDE2C68B36A; Fri, 6 May 2022 16:58:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9FA5868B2AE for ; Fri, 6 May 2022 16:57:58 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 246DvvRX029379 for ; Fri, 6 May 2022 15:57:57 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 65200E00F5; Fri, 6 May 2022 15:57:57 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 May 2022 15:57:51 +0200 Message-Id: <20220506135751.112173-1-george@nsup.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Fri, 06 May 2022 15:57:57 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH] lavu/common: fix PUT_UTF8() length 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: EBVDf++F9BnQ Ensure the input is <= 31 bits because otherwise it would produce very invalid UTF-8. Document that the length can be up to 6 bytes, because that is what the code does. The FLAC encoder abuses UTF-8 to store 32-bits integers, limiting PUT_UTF8() to 21 bits might affect some real cases negatively. Signed-off-by: Nicolas George --- libavutil/common.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavutil/common.h b/libavutil/common.h index fd1404be6c..7a71be3c81 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -505,7 +505,9 @@ static av_always_inline av_const int av_parity_c(uint32_t v) /** * @def PUT_UTF8(val, tmp, PUT_BYTE) - * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). + * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 6 + * bytes long, but codes more than 4 bytes long, i.e. codepoints above + * 0x001FFFFF, are deprecated). * @param val is an input-only argument and should be of type uint32_t. It holds * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If * val is given as a function it is executed only once. @@ -522,7 +524,7 @@ static av_always_inline av_const int av_parity_c(uint32_t v) #define PUT_UTF8(val, tmp, PUT_BYTE)\ {\ int bytes, shift;\ - uint32_t in = val;\ + uint32_t in = val & 0x7FFFFFFF;\ if (in < 0x80) {\ tmp = in;\ PUT_BYTE\