freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] Question about cidparse.c/cid_parser_new( )


From: mpsuzuki
Subject: Re: [ft-devel] Question about cidparse.c/cid_parser_new( )
Date: Tue, 8 Nov 2005 23:18:58 +0900

On Tue, 8 Nov 2005 19:17:02 +0900
address@hidden wrote:

>On Tue, 08 Nov 2005 10:12:19 +0100 (CET)
>Werner LEMBERG <address@hidden> wrote:
>
>>
>>> And I think there should be more change in this code section:
>>> 'limit' should be reset by 'buffer + readsize' in where readsize is
>>> actual read size.
>>
>>Please provide a patch.
>
>Excuse me, give me 4 hours.

I've written 2 patchs to fix a bug reported by Mr. Taek Kwan Lee.
I want to hear comments which is easier to maintain in future.

Regards,
mpsuzuki



Following is the first one. Shorter.

Index: src/cid/cidparse.c
===================================================================
RCS file: /cvsroot/freetype/freetype2/src/cid/cidparse.c,v
retrieving revision 1.44
diff -u -r1.44 cidparse.c
--- src/cid/cidparse.c  13 Feb 2005 21:42:42 -0000      1.44
+++ src/cid/cidparse.c  8 Nov 2005 14:10:00 -0000
@@ -101,10 +101,24 @@
 
       p = buffer + buff_len;
 
-      if ( FT_STREAM_READ( p, 256 + 10 - buff_len ) )
-        goto Exit;
+      {
+        FT_ULong  oldpos       = FT_STREAM_POS();
+        FT_ULong  size         = stream->size - oldpos;
+        FT_Int    max_read_len = 256 + 10 - buff_len;
+
+
+        if ( FT_STREAM_READ( p, FT_MIN( max_read_len, size ) ) )
+          goto Exit;
+
+        if ( max_read_len > size )
+        {
+          limit = p + size - 10;
+          top_position = FT_STREAM_POS() - size - 10;
+        }
+        else
+          top_position = FT_STREAM_POS() - buff_len;
+      }
 
-      top_position = FT_STREAM_POS() - buff_len;
       buff_len     = 256 + 10;
 
       /* look for `StartData' */


The second one is deep rewriting and make the function shoter,
so I attach modified one.

  Again:
    /* now, read the rest of the file until we find a `StartData' */
    {
      FT_Byte   buffer[256 + 10];
      FT_Int    read_len = 256 + 10;
      FT_Byte*  p        = buffer;


      for ( offset = (FT_ULong)FT_STREAM_POS(); ; offset += 256 )
      {
        FT_Int    stream_len;
        FT_Byte*  limit;


        stream_len = stream->size - FT_STREAM_POS();
        if ( stream_len == 0 )
          goto Exit;

        read_len = FT_MIN( read_len, stream_len );
        if ( FT_STREAM_READ( p, read_len ) )
          goto Exit;

        if ( read_len < 256 )
          p[read_len]  = '\0';

        limit = p + read_len - 10;

        for ( p = buffer; p < limit; p++ )
        {
          if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 )
          {
            /* save offset of binary data after `StartData' */
            offset += p - buffer + 10;
            goto Found;
          }
        }

        FT_MEM_MOVE( buffer, p, 10 );
        read_len = 256;
        p = buffer + 10;
      }
    }

  Found:

---------------------------------

Attachment: src_cid_cidparse_fix1.c.patch
Description: Binary data

Attachment: src_cid_cidparse_fix2.c.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]