[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft-devel] [PATCH] Read unsigned int from font file to avoid sign extens
From: |
Kan-Ru Chen |
Subject: |
[ft-devel] [PATCH] Read unsigned int from font file to avoid sign extension |
Date: |
Tue, 12 Apr 2011 01:06:46 +0800 |
User-agent: |
Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) |
Hi,
I was debugging this PDF rendering bug[1] that has been fixed by
freetype 2.4.4 recently[2] thanks to the `tt_check_trickyness' update.
[1]: http://bugs.debian.org/591094
[2]: https://savannah.nongnu.org/bugs/?31645
Although I did not see the bug in 32bit environment, it did appear in
64bit environment, on the same PDF file. Bad smell.
Set FT2_DEBUG to any:2 and load the attached PDF file:
32bit
tag offset length checksum
----------------------------------
cvt 0000009c 000002e4 05bcf058
fpgm 00000380 000087c4 28233bf1
glyf 00008d6c 00000ffe 00000000
head 00017b90 00000036 b8417ef6
hhea 00008b44 00000024 07be58bc
hmtx 00014f30 00002c60 00000000
loca 00009d6c 0000b1c4 00000000
maxp 00008b68 00000020 6fa88e54
prep 00008b88 000001e1 a344a1eb
64bit
tag offset length checksum
----------------------------------
cvt 0000009c 000002e4 05bcf058
fpgm 00000380 000087c4 28233bf1
glyf 00008d6c 00000ffe 00000000
head 00017b90 00000036 ffffffffb8417ef6
hhea 00008b44 00000024 07be58bc
hmtx 00014f30 00002c60 00000000
loca 00009d6c 0000b1c4 00000000
maxp 00008b68 00000020 6fa88e54
prep 00008b88 000001e1 ffffffffa344a1eb
The log suggests that there might some underlying problems in the stream
function, FT_GET_ULONG.
FT_GET_ULONG is defined as FT_GET_MACRO( FT_Stream_GetLong, FT_ULong )
which casts a probably sign extended long to a unsigned long, thus the
0xffffffff prefix.
I don't know which approach to fix this issue is desired, so I'm
proposing two patches here.
>From 5b314658f2d89fb36ecae19dd9600d12707325a2 Mon Sep 17 00:00:00 2001
From: Kan-Ru Chen <address@hidden>
Date: Tue, 12 Apr 2011 00:14:43 +0800
Subject: [PATCH] Read unsigned int from font file to avoid sign extension
Read unsigned integer from font file directly. If the value was
converted from a signed integer to a unsigned integer, it will be
wrong because of sign extension that has been done.
For example 0xa344a1eb will become 0xffffffffa344a1eb
---
include/freetype/internal/ftstream.h | 62 ++++++--
src/base/ftstream.c | 317 ++++++++++++++++++++++++++++++++++
2 files changed, 368 insertions(+), 11 deletions(-)
diff --git a/include/freetype/internal/ftstream.h
b/include/freetype/internal/ftstream.h
index a91eb72..3f3ecca 100644
--- a/include/freetype/internal/ftstream.h
+++ b/include/freetype/internal/ftstream.h
@@ -293,17 +293,17 @@ FT_BEGIN_HEADER
#define FT_GET_CHAR() FT_GET_MACRO( FT_Stream_GetChar, FT_Char )
#define FT_GET_BYTE() FT_GET_MACRO( FT_Stream_GetChar, FT_Byte )
#define FT_GET_SHORT() FT_GET_MACRO( FT_Stream_GetShort, FT_Short )
-#define FT_GET_USHORT() FT_GET_MACRO( FT_Stream_GetShort, FT_UShort )
+#define FT_GET_USHORT() FT_GET_MACRO( FT_Stream_GetUShort, FT_UShort )
#define FT_GET_OFF3() FT_GET_MACRO( FT_Stream_GetOffset, FT_Long )
-#define FT_GET_UOFF3() FT_GET_MACRO( FT_Stream_GetOffset, FT_ULong )
+#define FT_GET_UOFF3() FT_GET_MACRO( FT_Stream_GetUOffset, FT_ULong )
#define FT_GET_LONG() FT_GET_MACRO( FT_Stream_GetLong, FT_Long )
-#define FT_GET_ULONG() FT_GET_MACRO( FT_Stream_GetLong, FT_ULong )
-#define FT_GET_TAG4() FT_GET_MACRO( FT_Stream_GetLong, FT_ULong )
+#define FT_GET_ULONG() FT_GET_MACRO( FT_Stream_GetULong, FT_ULong )
+#define FT_GET_TAG4() FT_GET_MACRO( FT_Stream_GetULong, FT_ULong )
#define FT_GET_SHORT_LE() FT_GET_MACRO( FT_Stream_GetShortLE, FT_Short )
-#define FT_GET_USHORT_LE() FT_GET_MACRO( FT_Stream_GetShortLE, FT_UShort )
+#define FT_GET_USHORT_LE() FT_GET_MACRO( FT_Stream_GetUShortLE, FT_UShort )
#define FT_GET_LONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_Long )
-#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_ULong )
+#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetULongLE, FT_ULong )
#endif
#define FT_READ_MACRO( func, type, var ) \
@@ -313,16 +313,16 @@ FT_BEGIN_HEADER
#define FT_READ_BYTE( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Byte,
var )
#define FT_READ_CHAR( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Char,
var )
#define FT_READ_SHORT( var ) FT_READ_MACRO( FT_Stream_ReadShort,
FT_Short, var )
-#define FT_READ_USHORT( var ) FT_READ_MACRO( FT_Stream_ReadShort,
FT_UShort, var )
+#define FT_READ_USHORT( var ) FT_READ_MACRO( FT_Stream_ReadUShort,
FT_UShort, var )
#define FT_READ_OFF3( var ) FT_READ_MACRO( FT_Stream_ReadOffset,
FT_Long, var )
-#define FT_READ_UOFF3( var ) FT_READ_MACRO( FT_Stream_ReadOffset,
FT_ULong, var )
+#define FT_READ_UOFF3( var ) FT_READ_MACRO( FT_Stream_ReadUOffset,
FT_ULong, var )
#define FT_READ_LONG( var ) FT_READ_MACRO( FT_Stream_ReadLong, FT_Long,
var )
-#define FT_READ_ULONG( var ) FT_READ_MACRO( FT_Stream_ReadLong, FT_ULong,
var )
+#define FT_READ_ULONG( var ) FT_READ_MACRO( FT_Stream_ReadULong,
FT_ULong, var )
#define FT_READ_SHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadShortLE,
FT_Short, var )
-#define FT_READ_USHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadShortLE,
FT_UShort, var )
+#define FT_READ_USHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadUShortLE,
FT_UShort, var )
#define FT_READ_LONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadLongLE,
FT_Long, var )
-#define FT_READ_ULONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadLongLE,
FT_ULong, var )
+#define FT_READ_ULONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadULongLE,
FT_ULong, var )
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
@@ -435,22 +435,42 @@ FT_BEGIN_HEADER
FT_BASE( FT_Short )
FT_Stream_GetShort( FT_Stream stream );
+ /* read a 16-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_UShort )
+ FT_Stream_GetUShort( FT_Stream stream );
+
/* read a 24-bit big-endian integer from an entered frame */
FT_BASE( FT_Long )
FT_Stream_GetOffset( FT_Stream stream );
+ /* read a 24-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetUOffset( FT_Stream stream );
+
/* read a 32-bit big-endian integer from an entered frame */
FT_BASE( FT_Long )
FT_Stream_GetLong( FT_Stream stream );
+ /* read a 32-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetULong( FT_Stream stream );
+
/* read a 16-bit little-endian integer from an entered frame */
FT_BASE( FT_Short )
FT_Stream_GetShortLE( FT_Stream stream );
+ /* read a 16-bit little-endian unsigned integer from an entered frame */
+ FT_BASE( FT_UShort )
+ FT_Stream_GetUShortLE( FT_Stream stream );
+
/* read a 32-bit little-endian integer from an entered frame */
FT_BASE( FT_Long )
FT_Stream_GetLongLE( FT_Stream stream );
+ /* read a 32-bit little-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetULongLE( FT_Stream stream );
+
/* read a byte from a stream */
FT_BASE( FT_Char )
@@ -462,6 +482,11 @@ FT_BEGIN_HEADER
FT_Stream_ReadShort( FT_Stream stream,
FT_Error* error );
+ /* read a 16-bit big-endian unsigned integer from a stream */
+ FT_BASE( FT_UShort )
+ FT_Stream_ReadUShort( FT_Stream stream,
+ FT_Error* error );
+
/* read a 24-bit big-endian integer from a stream */
FT_BASE( FT_Long )
FT_Stream_ReadOffset( FT_Stream stream,
@@ -472,16 +497,31 @@ FT_BEGIN_HEADER
FT_Stream_ReadLong( FT_Stream stream,
FT_Error* error );
+ /* read a 32-bit big-endian unsigned integer from a stream */
+ FT_BASE( FT_ULong )
+ FT_Stream_ReadULong( FT_Stream stream,
+ FT_Error* error );
+
/* read a 16-bit little-endian integer from a stream */
FT_BASE( FT_Short )
FT_Stream_ReadShortLE( FT_Stream stream,
FT_Error* error );
+ /* read a 16-bit little-endian unsigned integer from a stream */
+ FT_BASE( FT_UShort )
+ FT_Stream_ReadUShortLE( FT_Stream stream,
+ FT_Error* error );
+
/* read a 32-bit little-endian integer from a stream */
FT_BASE( FT_Long )
FT_Stream_ReadLongLE( FT_Stream stream,
FT_Error* error );
+ /* read a 32-bit little-endian unsigned integer from a stream */
+ FT_BASE( FT_ULong )
+ FT_Stream_ReadULongLE( FT_Stream stream,
+ FT_Error* error );
+
/* Read a structure from a stream. The structure must be described */
/* by an array of FT_Frame_Field records. */
FT_BASE( FT_Error )
diff --git a/src/base/ftstream.c b/src/base/ftstream.c
index 210aaa4..1e0f05b 100644
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -372,6 +372,24 @@
return result;
}
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShort( FT_Stream stream )
+ {
+ FT_Byte* p;
+ FT_Short result;
+
+
+ FT_ASSERT( stream && stream->cursor );
+
+ result = 0;
+ p = stream->cursor;
+ if ( p + 1 < stream->limit )
+ result = FT_NEXT_USHORT( p );
+ stream->cursor = p;
+
+ return result;
+ }
+
FT_BASE_DEF( FT_Short )
FT_Stream_GetShortLE( FT_Stream stream )
@@ -391,6 +409,24 @@
return result;
}
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShortLE( FT_Stream stream )
+ {
+ FT_Byte* p;
+ FT_Short result;
+
+
+ FT_ASSERT( stream && stream->cursor );
+
+ result = 0;
+ p = stream->cursor;
+ if ( p + 1 < stream->limit )
+ result = FT_NEXT_USHORT_LE( p );
+ stream->cursor = p;
+
+ return result;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_GetOffset( FT_Stream stream )
@@ -409,6 +445,23 @@
return result;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetUOffset( FT_Stream stream )
+ {
+ FT_Byte* p;
+ FT_Long result;
+
+
+ FT_ASSERT( stream && stream->cursor );
+
+ result = 0;
+ p = stream->cursor;
+ if ( p + 2 < stream->limit )
+ result = FT_NEXT_UOFF3( p );
+ stream->cursor = p;
+ return result;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_GetLong( FT_Stream stream )
@@ -427,6 +480,23 @@
return result;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULong( FT_Stream stream )
+ {
+ FT_Byte* p;
+ FT_Long result;
+
+
+ FT_ASSERT( stream && stream->cursor );
+
+ result = 0;
+ p = stream->cursor;
+ if ( p + 3 < stream->limit )
+ result = FT_NEXT_ULONG( p );
+ stream->cursor = p;
+ return result;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_GetLongLE( FT_Stream stream )
@@ -445,6 +515,23 @@
return result;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULongLE( FT_Stream stream )
+ {
+ FT_Byte* p;
+ FT_Long result;
+
+
+ FT_ASSERT( stream && stream->cursor );
+
+ result = 0;
+ p = stream->cursor;
+ if ( p + 3 < stream->limit )
+ result = FT_NEXT_ULONG_LE( p );
+ stream->cursor = p;
+ return result;
+ }
+
FT_BASE_DEF( FT_Char )
FT_Stream_ReadChar( FT_Stream stream,
@@ -529,6 +616,52 @@
return 0;
}
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShort( FT_Stream stream,
+ FT_Error* error )
+ {
+ FT_Byte reads[2];
+ FT_Byte* p = 0;
+ FT_Short result = 0;
+
+
+ FT_ASSERT( stream );
+
+ *error = FT_Err_Ok;
+
+ if ( stream->pos + 1 < stream->size )
+ {
+ if ( stream->read )
+ {
+ if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
+ goto Fail;
+
+ p = reads;
+ }
+ else
+ {
+ p = stream->base + stream->pos;
+ }
+
+ if ( p )
+ result = FT_NEXT_USHORT( p );
+ }
+ else
+ goto Fail;
+
+ stream->pos += 2;
+
+ return result;
+
+ Fail:
+ *error = FT_Err_Invalid_Stream_Operation;
+ FT_ERROR(( "FT_Stream_ReadUShort:"
+ " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
+ stream->pos, stream->size ));
+
+ return 0;
+ }
+
FT_BASE_DEF( FT_Short )
FT_Stream_ReadShortLE( FT_Stream stream,
@@ -576,6 +709,52 @@
return 0;
}
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShortLE( FT_Stream stream,
+ FT_Error* error )
+ {
+ FT_Byte reads[2];
+ FT_Byte* p = 0;
+ FT_Short result = 0;
+
+
+ FT_ASSERT( stream );
+
+ *error = FT_Err_Ok;
+
+ if ( stream->pos + 1 < stream->size )
+ {
+ if ( stream->read )
+ {
+ if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
+ goto Fail;
+
+ p = reads;
+ }
+ else
+ {
+ p = stream->base + stream->pos;
+ }
+
+ if ( p )
+ result = FT_NEXT_USHORT_LE( p );
+ }
+ else
+ goto Fail;
+
+ stream->pos += 2;
+
+ return result;
+
+ Fail:
+ *error = FT_Err_Invalid_Stream_Operation;
+ FT_ERROR(( "FT_Stream_ReadUShortLE:"
+ " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
+ stream->pos, stream->size ));
+
+ return 0;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_ReadOffset( FT_Stream stream,
@@ -623,6 +802,52 @@
return 0;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadUOffset( FT_Stream stream,
+ FT_Error* error )
+ {
+ FT_Byte reads[3];
+ FT_Byte* p = 0;
+ FT_Long result = 0;
+
+
+ FT_ASSERT( stream );
+
+ *error = FT_Err_Ok;
+
+ if ( stream->pos + 2 < stream->size )
+ {
+ if ( stream->read )
+ {
+ if (stream->read( stream, stream->pos, reads, 3L ) != 3L )
+ goto Fail;
+
+ p = reads;
+ }
+ else
+ {
+ p = stream->base + stream->pos;
+ }
+
+ if ( p )
+ result = FT_NEXT_UOFF3( p );
+ }
+ else
+ goto Fail;
+
+ stream->pos += 3;
+
+ return result;
+
+ Fail:
+ *error = FT_Err_Invalid_Stream_Operation;
+ FT_ERROR(( "FT_Stream_ReadUOffset:"
+ " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
+ stream->pos, stream->size ));
+
+ return 0;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_ReadLong( FT_Stream stream,
@@ -670,6 +895,52 @@
return 0;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULong( FT_Stream stream,
+ FT_Error* error )
+ {
+ FT_Byte reads[4];
+ FT_Byte* p = 0;
+ FT_Long result = 0;
+
+
+ FT_ASSERT( stream );
+
+ *error = FT_Err_Ok;
+
+ if ( stream->pos + 3 < stream->size )
+ {
+ if ( stream->read )
+ {
+ if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
+ goto Fail;
+
+ p = reads;
+ }
+ else
+ {
+ p = stream->base + stream->pos;
+ }
+
+ if ( p )
+ result = FT_NEXT_ULONG( p );
+ }
+ else
+ goto Fail;
+
+ stream->pos += 4;
+
+ return result;
+
+ Fail:
+ *error = FT_Err_Invalid_Stream_Operation;
+ FT_ERROR(( "FT_Stream_ReadULong:"
+ " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
+ stream->pos, stream->size ));
+
+ return 0;
+ }
+
FT_BASE_DEF( FT_Long )
FT_Stream_ReadLongLE( FT_Stream stream,
@@ -717,6 +988,52 @@
return 0;
}
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULongLE( FT_Stream stream,
+ FT_Error* error )
+ {
+ FT_Byte reads[4];
+ FT_Byte* p = 0;
+ FT_Long result = 0;
+
+
+ FT_ASSERT( stream );
+
+ *error = FT_Err_Ok;
+
+ if ( stream->pos + 3 < stream->size )
+ {
+ if ( stream->read )
+ {
+ if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
+ goto Fail;
+
+ p = reads;
+ }
+ else
+ {
+ p = stream->base + stream->pos;
+ }
+
+ if ( p )
+ result = FT_NEXT_ULONG_LE( p );
+ }
+ else
+ goto Fail;
+
+ stream->pos += 4;
+
+ return result;
+
+ Fail:
+ *error = FT_Err_Invalid_Stream_Operation;
+ FT_ERROR(( "FT_Stream_ReadULongLE:"
+ " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
+ stream->pos, stream->size ));
+
+ return 0;
+ }
+
FT_BASE_DEF( FT_Error )
FT_Stream_ReadFields( FT_Stream stream,
--
1.7.4.1
>From 48eb706b69e98eeba5151e92829aa16fc9464b65 Mon Sep 17 00:00:00 2001
From: Kan-Ru Chen <address@hidden>
Date: Tue, 12 Apr 2011 00:31:45 +0800
Subject: [PATCH] Read unsigned int from font file to avoid sign extension
Read unsigned integer from font file then convert to signed one if
needed. If the value was converted from a signed integer to a unsigned
integer, it will be wrong because of sign extension that has been
done. For example 0xa344a1eb will become 0xffffffffa344a1eb.
The reverse is correct because the integer size is same.
---
include/freetype/internal/ftstream.h | 112 +++++++++++++++++-----------------
src/base/ftstream.c | 70 +++++++++++-----------
2 files changed, 91 insertions(+), 91 deletions(-)
diff --git a/include/freetype/internal/ftstream.h
b/include/freetype/internal/ftstream.h
index a91eb72..6298aad 100644
--- a/include/freetype/internal/ftstream.h
+++ b/include/freetype/internal/ftstream.h
@@ -292,18 +292,18 @@ FT_BEGIN_HEADER
#define FT_GET_CHAR() FT_GET_MACRO( FT_Stream_GetChar, FT_Char )
#define FT_GET_BYTE() FT_GET_MACRO( FT_Stream_GetChar, FT_Byte )
-#define FT_GET_SHORT() FT_GET_MACRO( FT_Stream_GetShort, FT_Short )
-#define FT_GET_USHORT() FT_GET_MACRO( FT_Stream_GetShort, FT_UShort )
-#define FT_GET_OFF3() FT_GET_MACRO( FT_Stream_GetOffset, FT_Long )
-#define FT_GET_UOFF3() FT_GET_MACRO( FT_Stream_GetOffset, FT_ULong )
-#define FT_GET_LONG() FT_GET_MACRO( FT_Stream_GetLong, FT_Long )
-#define FT_GET_ULONG() FT_GET_MACRO( FT_Stream_GetLong, FT_ULong )
-#define FT_GET_TAG4() FT_GET_MACRO( FT_Stream_GetLong, FT_ULong )
-
-#define FT_GET_SHORT_LE() FT_GET_MACRO( FT_Stream_GetShortLE, FT_Short )
-#define FT_GET_USHORT_LE() FT_GET_MACRO( FT_Stream_GetShortLE, FT_UShort )
-#define FT_GET_LONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_Long )
-#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_ULong )
+#define FT_GET_SHORT() FT_GET_MACRO( FT_Stream_GetUShort, FT_Short )
+#define FT_GET_USHORT() FT_GET_MACRO( FT_Stream_GetUShort, FT_UShort )
+#define FT_GET_OFF3() FT_GET_MACRO( FT_Stream_GetUOffset, FT_Long )
+#define FT_GET_UOFF3() FT_GET_MACRO( FT_Stream_GetUOffset, FT_ULong )
+#define FT_GET_LONG() FT_GET_MACRO( FT_Stream_GetULong, FT_Long )
+#define FT_GET_ULONG() FT_GET_MACRO( FT_Stream_GetULong, FT_ULong )
+#define FT_GET_TAG4() FT_GET_MACRO( FT_Stream_GetULong, FT_ULong )
+
+#define FT_GET_SHORT_LE() FT_GET_MACRO( FT_Stream_GetUShortLE, FT_Short )
+#define FT_GET_USHORT_LE() FT_GET_MACRO( FT_Stream_GetUShortLE, FT_UShort )
+#define FT_GET_LONG_LE() FT_GET_MACRO( FT_Stream_GetULongLE, FT_Long )
+#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetULongLE, FT_ULong )
#endif
#define FT_READ_MACRO( func, type, var ) \
@@ -312,17 +312,17 @@ FT_BEGIN_HEADER
#define FT_READ_BYTE( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Byte,
var )
#define FT_READ_CHAR( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Char,
var )
-#define FT_READ_SHORT( var ) FT_READ_MACRO( FT_Stream_ReadShort,
FT_Short, var )
-#define FT_READ_USHORT( var ) FT_READ_MACRO( FT_Stream_ReadShort,
FT_UShort, var )
-#define FT_READ_OFF3( var ) FT_READ_MACRO( FT_Stream_ReadOffset,
FT_Long, var )
-#define FT_READ_UOFF3( var ) FT_READ_MACRO( FT_Stream_ReadOffset,
FT_ULong, var )
-#define FT_READ_LONG( var ) FT_READ_MACRO( FT_Stream_ReadLong, FT_Long,
var )
-#define FT_READ_ULONG( var ) FT_READ_MACRO( FT_Stream_ReadLong, FT_ULong,
var )
+#define FT_READ_SHORT( var ) FT_READ_MACRO( FT_Stream_ReadUShort,
FT_Short, var )
+#define FT_READ_USHORT( var ) FT_READ_MACRO( FT_Stream_ReadUShort,
FT_UShort, var )
+#define FT_READ_OFF3( var ) FT_READ_MACRO( FT_Stream_ReadUOffset,
FT_Long, var )
+#define FT_READ_UOFF3( var ) FT_READ_MACRO( FT_Stream_ReadUOffset,
FT_ULong, var )
+#define FT_READ_LONG( var ) FT_READ_MACRO( FT_Stream_ReadULong, FT_Long,
var )
+#define FT_READ_ULONG( var ) FT_READ_MACRO( FT_Stream_ReadULong,
FT_ULong, var )
-#define FT_READ_SHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadShortLE,
FT_Short, var )
-#define FT_READ_USHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadShortLE,
FT_UShort, var )
-#define FT_READ_LONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadLongLE,
FT_Long, var )
-#define FT_READ_ULONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadLongLE,
FT_ULong, var )
+#define FT_READ_SHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadUShortLE,
FT_Short, var )
+#define FT_READ_USHORT_LE( var ) FT_READ_MACRO( FT_Stream_ReadUShortLE,
FT_UShort, var )
+#define FT_READ_LONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadULongLE,
FT_Long, var )
+#define FT_READ_ULONG_LE( var ) FT_READ_MACRO( FT_Stream_ReadULongLE,
FT_ULong, var )
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
@@ -431,25 +431,25 @@ FT_BEGIN_HEADER
FT_BASE( FT_Char )
FT_Stream_GetChar( FT_Stream stream );
- /* read a 16-bit big-endian integer from an entered frame */
- FT_BASE( FT_Short )
- FT_Stream_GetShort( FT_Stream stream );
+ /* read a 16-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_UShort )
+ FT_Stream_GetUShort( FT_Stream stream );
- /* read a 24-bit big-endian integer from an entered frame */
- FT_BASE( FT_Long )
- FT_Stream_GetOffset( FT_Stream stream );
+ /* read a 24-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetUOffset( FT_Stream stream );
- /* read a 32-bit big-endian integer from an entered frame */
- FT_BASE( FT_Long )
- FT_Stream_GetLong( FT_Stream stream );
+ /* read a 32-bit big-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetULong( FT_Stream stream );
- /* read a 16-bit little-endian integer from an entered frame */
- FT_BASE( FT_Short )
- FT_Stream_GetShortLE( FT_Stream stream );
+ /* read a 16-bit little-endian unsigned integer from an entered frame */
+ FT_BASE( FT_UShort )
+ FT_Stream_GetUShortLE( FT_Stream stream );
- /* read a 32-bit little-endian integer from an entered frame */
- FT_BASE( FT_Long )
- FT_Stream_GetLongLE( FT_Stream stream );
+ /* read a 32-bit little-endian unsigned integer from an entered frame */
+ FT_BASE( FT_ULong )
+ FT_Stream_GetULongLE( FT_Stream stream );
/* read a byte from a stream */
@@ -457,30 +457,30 @@ FT_BEGIN_HEADER
FT_Stream_ReadChar( FT_Stream stream,
FT_Error* error );
- /* read a 16-bit big-endian integer from a stream */
- FT_BASE( FT_Short )
- FT_Stream_ReadShort( FT_Stream stream,
- FT_Error* error );
-
- /* read a 24-bit big-endian integer from a stream */
- FT_BASE( FT_Long )
- FT_Stream_ReadOffset( FT_Stream stream,
+ /* read a 16-bit big-endian unsigned integer from a stream */
+ FT_BASE( FT_UShort )
+ FT_Stream_ReadUShort( FT_Stream stream,
FT_Error* error );
+ /* read a 24-bit big-endian unsigned integer from a stream */
+ FT_BASE( FT_ULong )
+ FT_Stream_ReadUOffset( FT_Stream stream,
+ FT_Error* error );
+
/* read a 32-bit big-endian integer from a stream */
- FT_BASE( FT_Long )
- FT_Stream_ReadLong( FT_Stream stream,
- FT_Error* error );
+ FT_BASE( FT_ULong )
+ FT_Stream_ReadULong( FT_Stream stream,
+ FT_Error* error );
- /* read a 16-bit little-endian integer from a stream */
- FT_BASE( FT_Short )
- FT_Stream_ReadShortLE( FT_Stream stream,
- FT_Error* error );
+ /* read a 16-bit little-endian unsigned integer from a stream */
+ FT_BASE( FT_UShort )
+ FT_Stream_ReadUShortLE( FT_Stream stream,
+ FT_Error* error );
- /* read a 32-bit little-endian integer from a stream */
- FT_BASE( FT_Long )
- FT_Stream_ReadLongLE( FT_Stream stream,
- FT_Error* error );
+ /* read a 32-bit little-endian unsigned integer from a stream */
+ FT_BASE( FT_ULong )
+ FT_Stream_ReadULongLE( FT_Stream stream,
+ FT_Error* error );
/* Read a structure from a stream. The structure must be described */
/* by an array of FT_Frame_Field records. */
diff --git a/src/base/ftstream.c b/src/base/ftstream.c
index 210aaa4..2ea7473 100644
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -354,8 +354,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_GetShort( FT_Stream stream )
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShort( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
@@ -366,15 +366,15 @@
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
- result = FT_NEXT_SHORT( p );
+ result = FT_NEXT_USHORT( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_GetShortLE( FT_Stream stream )
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_GetUShortLE( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
@@ -385,15 +385,15 @@
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
- result = FT_NEXT_SHORT_LE( p );
+ result = FT_NEXT_USHORT_LE( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetOffset( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetUOffset( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -404,14 +404,14 @@
result = 0;
p = stream->cursor;
if ( p + 2 < stream->limit )
- result = FT_NEXT_OFF3( p );
+ result = FT_NEXT_UOFF3( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetLong( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULong( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -422,14 +422,14 @@
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
- result = FT_NEXT_LONG( p );
+ result = FT_NEXT_ULONG( p );
stream->cursor = p;
return result;
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_GetLongLE( FT_Stream stream )
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_GetULongLE( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
@@ -440,7 +440,7 @@
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
- result = FT_NEXT_LONG_LE( p );
+ result = FT_NEXT_ULONG_LE( p );
stream->cursor = p;
return result;
}
@@ -483,8 +483,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_ReadShort( FT_Stream stream,
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShort( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
@@ -511,7 +511,7 @@
}
if ( p )
- result = FT_NEXT_SHORT( p );
+ result = FT_NEXT_USHORT( p );
}
else
goto Fail;
@@ -522,7 +522,7 @@
Fail:
*error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadShort:"
+ FT_ERROR(( "FT_Stream_ReadUShort:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -530,8 +530,8 @@
}
- FT_BASE_DEF( FT_Short )
- FT_Stream_ReadShortLE( FT_Stream stream,
+ FT_BASE_DEF( FT_UShort )
+ FT_Stream_ReadUShortLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
@@ -558,7 +558,7 @@
}
if ( p )
- result = FT_NEXT_SHORT_LE( p );
+ result = FT_NEXT_USHORT_LE( p );
}
else
goto Fail;
@@ -569,7 +569,7 @@
Fail:
*error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadShortLE:"
+ FT_ERROR(( "FT_Stream_ReadUShortLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -577,8 +577,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadOffset( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadUOffset( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[3];
@@ -605,7 +605,7 @@
}
if ( p )
- result = FT_NEXT_OFF3( p );
+ result = FT_NEXT_UOFF3( p );
}
else
goto Fail;
@@ -616,7 +616,7 @@
Fail:
*error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadOffset:"
+ FT_ERROR(( "FT_Stream_ReadUOffset:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -624,8 +624,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadLong( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULong( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
@@ -652,7 +652,7 @@
}
if ( p )
- result = FT_NEXT_LONG( p );
+ result = FT_NEXT_ULONG( p );
}
else
goto Fail;
@@ -663,7 +663,7 @@
Fail:
*error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadLong:"
+ FT_ERROR(( "FT_Stream_ReadULong:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
@@ -671,8 +671,8 @@
}
- FT_BASE_DEF( FT_Long )
- FT_Stream_ReadLongLE( FT_Stream stream,
+ FT_BASE_DEF( FT_ULong )
+ FT_Stream_ReadULongLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
@@ -699,7 +699,7 @@
}
if ( p )
- result = FT_NEXT_LONG_LE( p );
+ result = FT_NEXT_ULONG_LE( p );
}
else
goto Fail;
@@ -710,7 +710,7 @@
Fail:
*error = FT_Err_Invalid_Stream_Operation;
- FT_ERROR(( "FT_Stream_ReadLongLE:"
+ FT_ERROR(( "FT_Stream_ReadULongLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
--
1.7.4.1
schedule.pdf
Description: schedule.pdf
- [ft-devel] [PATCH] Read unsigned int from font file to avoid sign extension,
Kan-Ru Chen <=