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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/ChangeLog b/ChangeLog
index fb8085e..c9422ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/builds/amiga/src/base/ftsystem.c b/builds/amiga/src/base/ftsystem.c
index 016f1e2..a261988 100644
--- a/builds/amiga/src/base/ftsystem.c
+++ b/builds/amiga/src/base/ftsystem.c
@@ -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 ));
diff --git a/builds/vms/ftsystem.c b/builds/vms/ftsystem.c
index 76bfae9..0c98f03 100644
--- a/builds/vms/ftsystem.c
+++ b/builds/vms/ftsystem.c
@@ -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,
diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c
index ba86005..66c5d76 100644
--- a/src/base/ftsystem.c
+++ b/src/base/ftsystem.c
@@ -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;