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
|