Commit 64b395cca690381c8bbc1b03852b669c995b9a3f

Werner Lemberg 2013-12-04T06:18:56

[sfnt] Fix handling of embedded bitmap strikes. This corrects the commit from 2013-11-21. Problem reported by Andrey Panov <panov@canopus.iacp.dvo.ru>. * src/sfnt/ttsbit.c (tt_sbit_decoder_load_bitmap): Fix logic to detect excessive bytes for bit-aligned bitmaps.

diff --git a/ChangeLog b/ChangeLog
index 59dc1f4..a1aa33e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-12-04  Werner Lemberg  <wl@gnu.org>
+
+	[sfnt] Fix handling of embedded bitmap strikes.
+
+	This corrects the commit from 2013-11-21.  Problem reported by
+	Andrey Panov <panov@canopus.iacp.dvo.ru>.
+
+	* src/sfnt/ttsbit.c (tt_sbit_decoder_load_bitmap): Fix logic to
+	detect excessive bytes for bit-aligned bitmaps.
+
 2013-12-03  Werner Lemberg  <wl@gnu.org>
 
 	[truetype] Remove dead code.
@@ -101,7 +111,7 @@
 
 2013-11-21  Werner Lemberg  <wl@gnu.org>
 
-	[truetype] Improve handling of buggy embedded bitmap strikes.
+	[sfnt] Improve handling of buggy embedded bitmap strikes.
 
 	We are now able to successfully load `AppleMyoungJo.ttf'.
 	Problem reported by Hin-Tak Leung <htl10@users.sourceforge.net>.
diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c
index 890e794..7469ff1 100644
--- a/src/sfnt/ttsbit.c
+++ b/src/sfnt/ttsbit.c
@@ -976,11 +976,21 @@
           /* an excessive number of bytes in the image: If it is equal to  */
           /* the value for a byte-aligned glyph, use the other loading     */
           /* routine.                                                      */
+          /*                                                               */
+          /* Note that for some (width,height) combinations, where the     */
+          /* width is not a multiple of 8, the sizes for bit- and          */
+          /* byte-aligned data are equal, for example (7,7) or (15,6).  We */
+          /* then prefer what `glyph_format' specifies.                    */
+
           FT_UInt  width  = decoder->metrics->width;
           FT_UInt  height = decoder->metrics->height;
 
+          FT_UInt  bit_size  = ( width * height + 7 ) >> 3;
+          FT_UInt  byte_size = height * ( ( width + 7 ) >> 3 );
+
 
-          if ( height * ( ( width + 7 ) >> 3 ) == (FT_UInt)( p_limit - p ) )
+          if ( bit_size < byte_size                  &&
+               byte_size == (FT_UInt)( p_limit - p ) )
             loader = tt_sbit_decoder_load_byte_aligned;
           else
             loader = tt_sbit_decoder_load_bit_aligned;