Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PR] libavformat/{apetag.c, id3v2enc.c}: use new av_str_is_ascii (PR #21813)
@ 2026-02-20 15:00 toots via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: toots via ffmpeg-devel @ 2026-02-20 15:00 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: toots

PR #21813 opened by toots
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21813
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21813.patch


>From df2960c5a83ca7582c46a2092de7ff9fcc7e6f05 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <romain.beauxis@gmail.com>
Date: Wed, 17 Dec 2025 18:05:13 -0600
Subject: [PATCH 1/2] libavutil: Add av_str_is_ascii().

---
 doc/APIchanges       | 3 +++
 libavutil/avstring.c | 6 ++++++
 libavutil/avstring.h | 5 +++++
 3 files changed, 14 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2b43139b48..9d54cf6112 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -26,6 +26,9 @@ API changes, most recent first:
 2025-12-xx - xxxxxxxxxx - lavf 62.x.xxx - avformat.h
   Add av_mime_codec_str
 
+2025-12-xx - xxxxxxxxxx - lavu 60.20.100 - avstring.h
+  Add av_str_is_ascii().
+
 2025-12-xx - xxxxxxxxxx - lavu 60.20.100 - hwcontext_vulkan.h
   Add av_vk_get_optional_instance_extensions().
   Add av_vk_get_optional_device_extensions().
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 281c5cdc88..4c61accbee 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -227,6 +227,12 @@ int av_strncasecmp(const char *a, const char *b, size_t n)
     return c1 - c2;
 }
 
+int av_str_is_ascii(const uint8_t *str)
+{
+    while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
+    return !*str;
+}
+
 char *av_strireplace(const char *str, const char *from, const char *to)
 {
     char *ret = NULL;
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 17f7b03db5..ad54603be1 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -268,6 +268,11 @@ int av_strncasecmp(const char *a, const char *b, size_t n);
  */
 char *av_strireplace(const char *str, const char *from, const char *to);
 
+/** Checks if a string is in ASCII format.
+ *  @returns 0 if string is not ASCII and 1 if it is.
+ */
+int av_str_is_ascii(const uint8_t *str);
+
 /**
  * Thread safe basename.
  * @param path the string to parse, on DOS both \ and / are considered separators.
-- 
2.52.0


>From e82361d0c6fcea06e8d5f8c83088e564f10507ec Mon Sep 17 00:00:00 2001
From: Romain Beauxis <romain.beauxis@gmail.com>
Date: Wed, 17 Dec 2025 18:05:32 -0600
Subject: [PATCH 2/2] libavformat/{apetag.c, id3v2enc.c}: use new
 av_str_is_ascii

---
 libavformat/apetag.c   |  9 ++-------
 libavformat/id3v2enc.c | 12 +++---------
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index 0989fcb094..dcf475c042 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -24,6 +24,7 @@
 
 #include "libavutil/dict.h"
 #include "libavutil/mem.h"
+#include "libavutil/avstring.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "apetag.h"
@@ -169,12 +170,6 @@ int64_t ff_ape_parse_tag(AVFormatContext *s)
     return tag_start;
 }
 
-static int string_is_ascii(const uint8_t *str)
-{
-    while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
-    return !*str;
-}
-
 int ff_ape_write_tag(AVFormatContext *s)
 {
     const AVDictionaryEntry *e = NULL;
@@ -189,7 +184,7 @@ int ff_ape_write_tag(AVFormatContext *s)
     while ((e = av_dict_iterate(s->metadata, e))) {
         int val_len;
 
-        if (!string_is_ascii(e->key)) {
+        if (!av_str_is_ascii(e->key)) {
             av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n");
             continue;
         }
diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
index ac907c2758..d0095f545e 100644
--- a/libavformat/id3v2enc.c
+++ b/libavformat/id3v2enc.c
@@ -38,12 +38,6 @@ static void id3v2_put_size(AVIOContext *pb, int size)
     avio_w8(pb, size       & 0x7f);
 }
 
-static int string_is_ascii(const uint8_t *str)
-{
-    while (*str && *str < 128) str++;
-    return !*str;
-}
-
 static void id3v2_encode_string(AVIOContext *pb, const uint8_t *str,
                                enum ID3v2Encoding enc)
 {
@@ -74,8 +68,8 @@ static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *
 
     /* check if the strings are ASCII-only and use UTF16 only if
      * they're not */
-    if (enc == ID3v2_ENCODING_UTF16BOM && string_is_ascii(str1) &&
-        (!str2 || string_is_ascii(str2)))
+    if (enc == ID3v2_ENCODING_UTF16BOM && av_str_is_ascii(str1) &&
+        (!str2 || av_str_is_ascii(str2)))
         enc = ID3v2_ENCODING_ISO8859;
 
     avio_w8(dyn_buf, enc);
@@ -390,7 +384,7 @@ int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
         desc = e->value;
 
     /* use UTF16 only for non-ASCII strings */
-    if (enc == ID3v2_ENCODING_UTF16BOM && string_is_ascii(desc))
+    if (enc == ID3v2_ENCODING_UTF16BOM && av_str_is_ascii(desc))
         enc = ID3v2_ENCODING_ISO8859;
 
     /* start writing */
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-02-20 15:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-20 15:00 [FFmpeg-devel] [PR] libavformat/{apetag.c, id3v2enc.c}: use new av_str_is_ascii (PR #21813) toots via ffmpeg-devel

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