[Bf-blender-cvs] [dbc097d6b8f] master: Fix error in blf_get_sample_text returning a pointer to stack memory

Campbell Barton noreply at git.blender.org
Fri Sep 30 07:03:46 CEST 2022


Commit: dbc097d6b8f8391832d8ffe051ca7ffaf37853fe
Author: Campbell Barton
Date:   Fri Sep 30 14:56:01 2022 +1000
Branches: master
https://developer.blender.org/rBdbc097d6b8f8391832d8ffe051ca7ffaf37853fe

Fix error in blf_get_sample_text returning a pointer to stack memory

Copy-by-value was used when iterating over unicode_samples which
then referenced an array from the value.

Resolve by referencing a const pointer to the unicode_sample array.

===================================================================

M	source/blender/blenfont/intern/blf_thumbs.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 2eed7418220..e4eed070e24 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -258,16 +258,18 @@ static const char32_t *blf_get_sample_text(FT_Face face)
                        count_bits_i((uint)os2_table->ulUnicodeRange4);
 
   for (uint i = 0; i < ARRAY_SIZE(unicode_samples); ++i) {
-    UnicodeSample s = unicode_samples[i];
-    if (os2_table && s.field && s.mask) {
+    const UnicodeSample *s = &unicode_samples[i];
+    if (os2_table && s->field && s->mask) {
       /* OS/2 Table contains 4 contiguous integers of script coverage bit flags. */
-      FT_ULong *field = &(os2_table->ulUnicodeRange1) + (s.field - 1);
-      if (!(*field & (FT_ULong)s.mask)) {
+      const FT_ULong *unicode_range = &os2_table->ulUnicodeRange1;
+      const size_t index = (s->field - 1);
+      BLI_assert(index < 4);
+      if (!(unicode_range[index] & (FT_ULong)s->mask)) {
         continue;
       }
     }
-    if (FT_Get_Char_Index(face, s.sample[0]) != 0) {
-      sample = s.sample;
+    if (FT_Get_Char_Index(face, s->sample[0]) != 0) {
+      sample = s->sample;
       break;
     }
   }



More information about the Bf-blender-cvs mailing list