Prevent to open a FT_Stream for zero-sized file on non-Unix.

builds/unix/ftsystem.c prevents to open an useless stream from
zero-sized file and returns FT_Err_Cannot_Open_Stream, but the
stream drivers for ANSI C, Amiga and VMS return useless streams.
For cross-platform consistency, all stream drivers should act
same.

* src/base/ftsystem.c (FT_Stream_Open): If the size of the opened
file is zero, FT_Err_Cannot_Open_Stream is returned.
* builds/amiga/src/base/ftsystem.c (FT_Stream_Open): Ditto.
* src/vms/ftsystem.c (FT_Stream_Open): Ditto.
This commit is contained in:
suzuki toshiya 2010-10-13 16:21:59 +09:00
parent 59eb9f8cfe
commit 4b71871418
4 changed files with 44 additions and 3 deletions

View File

@ -1,3 +1,18 @@
2010-10-13 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
Prevent to open a FT_Stream for zero-sized file on non-Unix.
builds/unix/ftsystem.c prevents to open an useless stream from
zero-sized file and returns FT_Err_Cannot_Open_Stream, but the
stream drivers for ANSI C, Amiga and VMS return useless streams.
For cross-platform consistency, all stream drivers should act
same.
* src/base/ftsystem.c (FT_Stream_Open): If the size of the opened
file is zero, FT_Err_Cannot_Open_Stream is returned.
* builds/amiga/src/base/ftsystem.c (FT_Stream_Open): Ditto.
* src/vms/ftsystem.c (FT_Stream_Open): Ditto.
2010-10-12 Werner Lemberg <wl@gnu.org>
Fix Savannah bug #31310.

View File

@ -442,6 +442,14 @@ Free_VecPooled( APTR poolHeader,
stream->read = ft_amiga_stream_io;
stream->close = ft_amiga_stream_close;
if ( !stream->size )
{
ft_amiga_stream_close( stream );
FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
return FT_Err_Cannot_Open_Stream;;
}
FT_TRACE1(( "FT_Stream_Open:" ));
FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n",
filepathname, stream->size ));

View File

@ -231,6 +231,13 @@
}
stream->size = stat_buf.st_size;
if ( !stream->size )
{
FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
goto Fail_Map;
}
stream->pos = 0;
stream->base = (unsigned char *)mmap( NULL,
stream->size,

View File

@ -229,6 +229,13 @@
if ( !stream )
return FT_Err_Invalid_Stream_Handle;
stream->descriptor.pointer = NULL;
stream->pathname.pointer = (char*)filepathname;
stream->base = 0;
stream->pos = 0;
stream->read = NULL;
stream->close = NULL;
file = ft_fopen( filepathname, "rb" );
if ( !file )
{
@ -240,12 +247,16 @@
ft_fseek( file, 0, SEEK_END );
stream->size = ft_ftell( file );
if ( !stream->size )
{
FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
ft_fclose( file );
return FT_Err_Cannot_Open_Stream;
}
ft_fseek( file, 0, SEEK_SET );
stream->descriptor.pointer = file;
stream->pathname.pointer = (char*)filepathname;
stream->pos = 0;
stream->read = ft_ansi_stream_io;
stream->close = ft_ansi_stream_close;