shithub: opus

Download patch

ref: e0ca05b1ec5ef4abbfed5f70623ed3e5ea77dd6b
parent: 6577534a80c833bd310276f1e2bd3254271bb86d
author: Jean-Marc Valin <[email protected]>
date: Thu Jun 30 12:25:03 EDT 2022

Adds fuzzing to CPU detection

Makes ti possible to randomize (with --enable-fuzzing) the CPU flags
so we can better test all the intrinsics implementations.

--- a/celt/arm/armcpu.c
+++ b/celt/arm/armcpu.c
@@ -156,7 +156,7 @@
    "your platform.  Reconfigure with --disable-rtcd (or send patches)."
 #endif
 
-int opus_select_arch(void)
+static int opus_select_arch_impl(void)
 {
   opus_uint32 flags = opus_cpu_capabilities();
   int arch = 0;
@@ -184,4 +184,11 @@
   return arch;
 }
 
+int opus_select_arch(void) {
+  int arch = opus_select_arch_impl();
+#ifdef FUZZING
+  arch = rand()%(arch+1);
+#endif
+  return arch;
+}
 #endif
--- a/celt/x86/x86cpu.c
+++ b/celt/x86/x86cpu.c
@@ -128,7 +128,7 @@
     }
 }
 
-int opus_select_arch(void)
+static int opus_select_arch_impl(void)
 {
     CPU_Feature cpu_feature;
     int arch;
@@ -160,6 +160,15 @@
     }
     arch++;
 
+    return arch;
+}
+
+int opus_select_arch(void) {
+    int arch = opus_select_arch_impl();
+#ifdef FUZZING
+    /* Randomly downgrade the architecture. */
+    arch = rand()%(arch+1);
+#endif
     return arch;
 }