Bug 1401227 - Cherry-pick patch 0d1262a41e019e4511071e339bb8aa018596a1fd from upstream freetype to avoid potential crash in premultiply_data. r=milan, a=sledru
authorJonathan Kew <jkew@mozilla.com>
Mon, 25 Sep 2017 17:30:53 +0100
changeset 434300 cfef69ffbc364c4401ffad973866bf70cffe115b
parent 434299 c89417bb5ce904ef935563aa0e7ab9fc93f20f6f
child 434301 dce8934980ff886428603bb4d8c45b42bc79bfa1
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmilan, sledru
bugs1401227
milestone57.0
Bug 1401227 - Cherry-pick patch 0d1262a41e019e4511071e339bb8aa018596a1fd from upstream freetype to avoid potential crash in premultiply_data. r=milan, a=sledru
modules/freetype2/src/sfnt/pngshim.c
--- a/modules/freetype2/src/sfnt/pngshim.c
+++ b/modules/freetype2/src/sfnt/pngshim.c
@@ -76,53 +76,55 @@
     /* version 2.8                                                    */
 #define vector_shuffle  __builtin_shufflevector
 #else
 #define vector_shuffle  __builtin_shuffle
 #endif
 
     typedef unsigned short  v82 __attribute__(( vector_size( 16 ) ));
 
+    if ( row_info->rowbytes > 15 )
+    {
+      /* process blocks of 16 bytes in one rush, which gives a nice speed-up */
+      limit = row_info->rowbytes - 16 + 1;
+      for ( ; i < limit; i += 16 )
+      {
+        unsigned char*  base = &data[i];
 
-    /* process blocks of 16 bytes in one rush, which gives a nice speed-up */
-    limit = row_info->rowbytes - 16 + 1;
-    for ( ; i < limit; i += 16 )
-    {
-      unsigned char*  base = &data[i];
-
-      v82  s, s0, s1, a;
+        v82  s, s0, s1, a;
 
-      /* clang <= 3.9 can't apply scalar values to vectors */
-      /* (or rather, it needs a different syntax)          */
-      v82  n0x80 = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
-      v82  n0xFF = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-      v82  n8    = { 8, 8, 8, 8, 8, 8, 8, 8 };
+        /* clang <= 3.9 can't apply scalar values to vectors */
+        /* (or rather, it needs a different syntax)          */
+        v82  n0x80 = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
+        v82  n0xFF = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+        v82  n8    = { 8, 8, 8, 8, 8, 8, 8, 8 };
 
-      v82  ma = { 1, 1, 3, 3, 5, 5, 7, 7 };
-      v82  o1 = { 0, 0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF };
-      v82  m0 = { 1, 0, 3, 2, 5, 4, 7, 6 };
+        v82  ma = { 1, 1, 3, 3, 5, 5, 7, 7 };
+        v82  o1 = { 0, 0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF };
+        v82  m0 = { 1, 0, 3, 2, 5, 4, 7, 6 };
 
 
-      memcpy( &s, base, 16 );               /* RGBA RGBA RGBA RGBA */
-      s0 = s & n0xFF;                       /*  R B  R B  R B  R B */
-      s1 = s >> n8;                         /*  G A  G A  G A  G A */
+        memcpy( &s, base, 16 );               /* RGBA RGBA RGBA RGBA */
+        s0 = s & n0xFF;                       /*  R B  R B  R B  R B */
+        s1 = s >> n8;                         /*  G A  G A  G A  G A */
 
-      a   = vector_shuffle( s1, ma );       /*  A A  A A  A A  A A */
-      s1 |= o1;                             /*  G 1  G 1  G 1  G 1 */
-      s0  = vector_shuffle( s0, m0 );       /*  B R  B R  B R  B R */
+        a   = vector_shuffle( s1, ma );       /*  A A  A A  A A  A A */
+        s1 |= o1;                             /*  G 1  G 1  G 1  G 1 */
+        s0  = vector_shuffle( s0, m0 );       /*  B R  B R  B R  B R */
 
-      s0 *= a;
-      s1 *= a;
-      s0 += n0x80;
-      s1 += n0x80;
-      s0  = ( s0 + ( s0 >> n8 ) ) >> n8;
-      s1  = ( s1 + ( s1 >> n8 ) ) >> n8;
+        s0 *= a;
+        s1 *= a;
+        s0 += n0x80;
+        s1 += n0x80;
+        s0  = ( s0 + ( s0 >> n8 ) ) >> n8;
+        s1  = ( s1 + ( s1 >> n8 ) ) >> n8;
 
-      s = s0 | ( s1 << n8 );
-      memcpy( base, &s, 16 );
+        s = s0 | ( s1 << n8 );
+        memcpy( base, &s, 16 );
+      }
     }
 #endif /* use `vector_size' */
 
     FT_UNUSED( png );
 
     limit = row_info->rowbytes;
     for ( ; i < limit; i += 4 )
     {