From: Nicolas George <george@nsup.org> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] lavu/common: fix PUT_UTF8() length Date: Fri, 6 May 2022 15:57:51 +0200 Message-ID: <20220506135751.112173-1-george@nsup.org> (raw) 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 <george@nsup.org> --- 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\ -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2022-05-06 13:58 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220506135751.112173-1-george@nsup.org \ --to=george@nsup.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git