[babl] babl: prevent loading extension modules with incorrect SIMD



commit 19b5e21308b917419e71649da4e7d1d439364aea
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Mar 15 12:56:16 2022 +0100

    babl: prevent loading extension modules with incorrect SIMD
    
    This now happens on top of bailing inside the individual modules -
    which in some cases is insufficient. This is likely sufficient
    to fix issue #69.

 babl/babl-extension.c | 15 +++++++++++----
 babl/babl-extension.h |  3 ++-
 babl/babl.c           | 27 +++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/babl/babl-extension.c b/babl/babl-extension.c
index 554c764a3..3063d46c7 100644
--- a/babl/babl-extension.c
+++ b/babl/babl-extension.c
@@ -247,7 +247,8 @@ babl_extension_load (const char *path)
 }
 
 static void
-babl_extension_load_dir (const char *base_path)
+babl_extension_load_dir (const char *base_path,
+                         const char **exclusion_patterns)
 {
   DIR *dir;
 
@@ -269,7 +270,12 @@ babl_extension_load_dir (const char *base_path)
               if ((extension = strrchr (dentry->d_name, '.')) != NULL &&
                   !strcmp (extension, SHREXT))
                 {
-                  babl_extension_load (path);
+                  int excluded = 0;
+                  for (int i = 0; exclusion_patterns[i]; i++)
+                    if (strstr (path, exclusion_patterns[i]))
+                      excluded = 1;
+                  if (!excluded)
+                    babl_extension_load (path);
                 }
 
               babl_free (path);
@@ -316,7 +322,8 @@ expand_path (char *path)
 /*  parse the provided colon seperated list of paths to search
  */
 void
-babl_extension_load_dir_list (const char *dir_list)
+babl_extension_load_dir_list (const char *dir_list,
+                              const char **exclusion_patterns)
 {
   int         eos = 0;
   const char *src;
@@ -339,7 +346,7 @@ babl_extension_load_dir_list (const char *dir_list)
           {
             char *expanded_path = expand_path (path);
             if (expanded_path) {
-                babl_extension_load_dir (expanded_path);
+                babl_extension_load_dir (expanded_path, exclusion_patterns);
                 babl_free (expanded_path);
             }
           }
diff --git a/babl/babl-extension.h b/babl/babl-extension.h
index 82e1d7e78..50fb73139 100644
--- a/babl/babl-extension.h
+++ b/babl/babl-extension.h
@@ -28,7 +28,8 @@ BABL_CLASS_DECLARE (extension);
  */
 
 const  Babl * babl_extension               (const char *name);
-void          babl_extension_load_dir_list (const char *dir_list);
+void          babl_extension_load_dir_list (const char *dir_list,
+                                            const char **exclusion_patterns);
 
 typedef struct
 {
diff --git a/babl/babl.c b/babl/babl.c
index 141396f9b..3cb86cdfa 100644
--- a/babl/babl.c
+++ b/babl/babl.c
@@ -127,12 +127,13 @@ babl_dir_list (void)
 }
 
 
-static void simd_init (void);
+static const char **simd_init (void);
 void
 babl_init (void)
 {
+  const char **exclusion_pattern;
   babl_cpu_accel_set_use (1);
-  simd_init ();
+  exclusion_pattern = simd_init ();
 
   if (ref_count++ == 0)
     {
@@ -155,7 +156,7 @@ babl_init (void)
       babl_sanity ();
 
       dir_list = babl_dir_list ();
-      babl_extension_load_dir_list (dir_list);
+      babl_extension_load_dir_list (dir_list, exclusion_pattern);
       babl_free (dir_list);
 
       if (!getenv ("BABL_INHIBIT_CACHE"))
@@ -263,12 +264,14 @@ babl_trc_new_arm_neon (const char *name,
 
 #endif
 
-static void simd_init (void)
+static const char **simd_init (void)
 {
+  static const char *exclude[] = {"neon-", "x86-64-v3", "x86-64-v2", NULL};
 #ifdef ARCH_X86_64
   BablCpuAccelFlags accel = babl_cpu_accel_get_support ();
   if ((accel & BABL_CPU_ACCEL_X86_64_V3) == BABL_CPU_ACCEL_X86_64_V3)
   {
+    static const char *exclude[] = {NULL};
     babl_base_init = babl_base_init_x86_64_v2; /// !!
                                                // this is correct,
                                                // it performs better
@@ -276,24 +279,40 @@ static void simd_init (void)
     babl_trc_new = babl_trc_new_x86_64_v2;
     babl_trc_lookup_by_name = babl_trc_lookup_by_name_x86_64_v2;
     _babl_space_add_universal_rgb = _babl_space_add_universal_rgb_x86_64_v3;
+    return exclude;
   }
   else if ((accel & BABL_CPU_ACCEL_X86_64_V2) == BABL_CPU_ACCEL_X86_64_V2)
   {
+    static const char *exclude[] = {"x86-64-v3-", NULL};
     babl_base_init = babl_base_init_x86_64_v2;
     babl_trc_new = babl_trc_new_x86_64_v2;
     babl_trc_lookup_by_name = babl_trc_lookup_by_name_x86_64_v2;
     _babl_space_add_universal_rgb = _babl_space_add_universal_rgb_x86_64_v2;
+    return exclude;
+  }
+  else
+  {
+    static const char *exclude[] = {"x86-64-v3-", "x86-64-v2-", NULL};
+    return exclude;
   }
 #endif
 #ifdef ARCH_ARM
   BablCpuAccelFlags accel = babl_cpu_accel_get_support ();
   if ((accel & BABL_CPU_ACCEL_ARM_NEON) == BABL_CPU_ACCEL_ARM_NEON)
   {
+    static const char *exclude[] = {NULL};
     babl_base_init = babl_base_init_arm_neon;
     babl_trc_new = babl_trc_new_arm_neon;
     babl_trc_lookup_by_name = babl_trc_lookup_by_name_arm_neon;
     _babl_space_add_universal_rgb = _babl_space_add_universal_rgb_arm_neon;
+    return exclude;
+  }
+  else
+  {
+    static const char *exclude[] = {"neon-", NULL};
+    return exclude;
   }
 #endif
+  return exclude;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]