PR #23421 opened by Marcos Ashton (MarcosAsh)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23421
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23421.patch

## Summary
The seven *_from_name() functions in pixdesc.c (color_range, color_primaries, 
color_transfer, color_space, chroma_location, alpha_mode) use av_strstart() for 
prefix matching, which returns incorrect results when one name is a prefix of 
another. av_color_space_from_name("ycgco-re") matches "ycgco" and returns 
AVCOL_SPC_YCGCO instead of AVCOL_SPC_YCGCO_RE; "ycgco-ro" has the same issue, 
as do the *_ext name lookups inside av_color_primaries_from_name and 
av_color_transfer_from_name.

This switches all eight call sites from av_strstart() to strcmp() for exact 
matching. No in-tree callers rely on prefix matching.


>From d5884cf46a3e810f3b60b7d257514740658b654d Mon Sep 17 00:00:00 2001
From: marcos ashton <[email protected]>
Date: Fri, 8 May 2026 15:22:18 +0100
Subject: [PATCH] libavutil/pixdesc: fix prefix matching in *_from_name()
 functions

The seven *_from_name() functions in pixdesc.c (color_range,
color_primaries, color_transfer, color_space, chroma_location,
alpha_mode) used av_strstart() for prefix matching, which returns
incorrect results when one name is a prefix of another.

av_color_space_from_name("ycgco-re") matched "ycgco" at index
AVCOL_SPC_YCGCO and returned 8 instead of AVCOL_SPC_YCGCO_RE.
av_color_space_from_name("ycgco-ro") had the same issue. The
*_ext name lookups inside av_color_primaries_from_name and
av_color_transfer_from_name had the same flaw.

Switch all eight call sites from av_strstart() to strcmp() for
exact matching. No in-tree callers rely on prefix matching.

Signed-off-by: marcos ashton <[email protected]>
---
 libavutil/pixdesc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 90f9596def..ba25a25617 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -3780,7 +3780,7 @@ int av_color_range_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_range_names); i++) {
-        if (av_strstart(name, color_range_names[i], NULL))
+        if (!strcmp(name, color_range_names[i]))
             return i;
     }
 
@@ -3805,7 +3805,7 @@ int av_color_primaries_from_name(const char *name)
         if (!color_primaries_names[i])
             continue;
 
-        if (av_strstart(name, color_primaries_names[i], NULL))
+        if (!strcmp(name, color_primaries_names[i]))
             return i;
     }
 
@@ -3813,7 +3813,7 @@ int av_color_primaries_from_name(const char *name)
         if (!color_primaries_names_ext[i])
             continue;
 
-        if (av_strstart(name, color_primaries_names_ext[i], NULL))
+        if (!strcmp(name, color_primaries_names_ext[i]))
             return AVCOL_PRI_EXT_BASE + i;
     }
 
@@ -3838,7 +3838,7 @@ int av_color_transfer_from_name(const char *name)
         if (!color_transfer_names[i])
             continue;
 
-        if (av_strstart(name, color_transfer_names[i], NULL))
+        if (!strcmp(name, color_transfer_names[i]))
             return i;
     }
 
@@ -3846,7 +3846,7 @@ int av_color_transfer_from_name(const char *name)
         if (!color_transfer_names_ext[i])
             continue;
 
-        if (av_strstart(name, color_transfer_names_ext[i], NULL))
+        if (!strcmp(name, color_transfer_names_ext[i]))
             return AVCOL_TRC_EXT_BASE + i;
     }
 
@@ -3867,7 +3867,7 @@ int av_color_space_from_name(const char *name)
         if (!color_space_names[i])
             continue;
 
-        if (av_strstart(name, color_space_names[i], NULL))
+        if (!strcmp(name, color_space_names[i]))
             return i;
     }
 
@@ -3888,7 +3888,7 @@ int av_chroma_location_from_name(const char *name)
         if (!chroma_location_names[i])
             continue;
 
-        if (av_strstart(name, chroma_location_names[i], NULL))
+        if (!strcmp(name, chroma_location_names[i]))
             return i;
     }
 
@@ -3930,7 +3930,7 @@ enum AVAlphaMode av_alpha_mode_from_name(const char *name)
         if (!alpha_mode_names[i])
             continue;
 
-        if (av_strstart(name, alpha_mode_names[i], NULL))
+        if (!strcmp(name, alpha_mode_names[i]))
             return i;
     }
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to