bugThe FreeType Project - Bugs: bug #21471, Stream reading bug in...

 
 

bug #21471: Stream reading bug in builds/unix/ftsystem.c

Submitted by:  Daniel Svoboda <dasvo>
Submitted on:  Tue 30 Oct 2007 08:38:00 AM UTC  
 
Severity: 3 - NormalItem Group: Incorrect behaviour
Status: FixedPrivacy: Public
Assigned to: suzuki toshiya <mpsuzuki>Open/Closed: Closed
Planned Release: 2.3.6

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 11 Sep 2008 02:39:58 PM UTC, comment #2:

I'm quite sorry for my silence about this issue.
When this report was posted, I was working for
the update of Mac OS X 64bit platform support,
and this issue was fixed by different way. Here
I quote my ChangeLog:

2007-11-20 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>

Fix MacOS legacy font support by Masatake Yamato on Mac OS X. It is
not working since 2.3.5. In FT_Open_New(), if FT_New_Stream()
cannot mmap() the specified file and cannot seek to head of the
specified file, it returns NULL stream and FT_Open_New() returns the
error immediately. On MacOS, most legacy MacOS fonts fall into such
a scenario because their data forks are zero-sized and cannot be
sought. To proceed to guessing of resource fork fonts, the
functions for legacy MacOS font must properly handle the NULL stream
returned by FT_New_Stream().

This issue was fixed since 2.3.6. I think your proposal
was very smart. But, I think returning a normal stream
for zero-sized file is not useful for the main task of
FreeType2 (because zero-sized file must not be working
font file), so returning NULL stream was not so bad idea.
If you have any scenario that returning a normal stream
(but cannot seek nor read at all) is better than NULL
stream, please let me know. I will do so.

suzuki toshiya <mpsuzuki>
Project AdministratorIn charge of this item.
Tue 30 Oct 2007 08:43:04 AM UTC, comment #1:

Suzuki-san, please take care of it.

Werner LEMBERG <wl>
Project Administrator
Tue 30 Oct 2007 08:38:00 AM UTC, original submission:

There is a bug in ftsystem.c in function FT_Stream_Open that when reading "resource fork only" Macintosh fonts, the FT_Stream_Open fails with FT_Err_Cannot_Open_Stream which makes the FreeType unusable for any Macintosh only fonts.

The problem is in the fact, that stream size in this case is 0, mmap returns NULL and the function tries to read the content which has size 0 bytes and the existing condition "if ( read_count <= 0 )" fails, because the expected read_count is actually 0.

Proposed solution for this problem:

Replace

total_read_count = 0;
do {
ssize_t read_count;

read_count = read( file,
stream->base + total_read_count,
stream->size - total_read_count );

if ( read_count <= 0 )
{
if ( read_count == -1 && errno == EINTR )
continue;

FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " error while `read'ing file `%s'\n", filepathname ));
goto Fail_Read;
}

total_read_count += read_count;

} while ( (unsigned long)total_read_count != stream->size );

By

if (stream->size > 0)
{
total_read_count = 0;
do {
ssize_t read_count;

read_count = read( file,
stream->base + total_read_count,
stream->size - total_read_count );

if ( read_count <= 0 )
{
if ( read_count == -1 && errno == EINTR )
continue;

FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " error while `read'ing file `%s'\n", filepathname ));
goto Fail_Read;
}

total_read_count += read_count;

} while ( (unsigned long)total_read_count != stream->size );
}

this code makes sure, that it doesn't try to read anything from stream when size is actually zero.

See attached file for proposed solution implemented.

Thanks,

Daniel

Daniel Svoboda <dasvo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #14254:  ftsystem.c added by dasvo (15KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by mpsuzuki (Posted a comment)
  • -unavailable- added by wl (Posted a comment)
  • -unavailable- added by dasvo (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 11 Sep 2008 02:39:58 PM UTCmpsuzukiStatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
      Planned ReleaseNone=>2.3.6
    Tue 30 Oct 2007 08:43:04 AM UTCwlStatusNone=>In Progress
      Assigned toNone=>mpsuzuki
    Tue 30 Oct 2007 08:38:01 AM UTCdasvoAttached File-=>Added ftsystem.c, #14254

    Back to the top


    Powered by Savane 3.1-cleanup1