ReactOS 0.4.16-dev-2354-g16de117
ftrfork.c File Reference
Include dependency graph for ftrfork.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   raccess
 

Functions

 FT_Raccess_Get_HeaderInfo (FT_Library library, FT_Stream stream, FT_Long rfork_offset, FT_Long *map_offset, FT_Long *rdata_pos)
 
static int ft_raccess_sort_ref_by_id (FT_RFork_Ref *a, FT_RFork_Ref *b)
 
 FT_Raccess_Get_DataOffsets (FT_Library library, FT_Stream stream, FT_Long map_offset, FT_Long rdata_pos, FT_Long tag, FT_Bool sort_by_res_id, FT_Long **offsets, FT_Long *count)
 
 FT_Raccess_Guess (FT_Library library, FT_Stream stream, char *base_name, char **new_names, FT_Long *offsets, FT_Error *errors)
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   raccess

Definition at line 34 of file ftrfork.c.

Function Documentation

◆ FT_Raccess_Get_DataOffsets()

FT_Raccess_Get_DataOffsets ( FT_Library  library,
FT_Stream  stream,
FT_Long  map_offset,
FT_Long  rdata_pos,
FT_Long  tag,
FT_Bool  sort_by_res_id,
FT_Long **  offsets,
FT_Long count 
)

Definition at line 184 of file ftrfork.c.

192 {
194 int i, j, cnt, subcnt;
195 FT_Long tag_internal, rpos;
198 FT_Long *offsets_internal = NULL;
200
201
202 FT_TRACE3(( "\n" ));
203 error = FT_Stream_Seek( stream, (FT_ULong)map_offset );
204 if ( error )
205 return error;
206
207 if ( FT_READ_SHORT( cnt ) )
208 return error;
209 cnt++;
210
211 /* `rpos' is a signed 16bit integer offset to resource records; the */
212 /* size of a resource record is 12 bytes. The map header is 28 bytes, */
213 /* and a type list needs 10 bytes or more. If we assume that the name */
214 /* list is empty and we have only a single entry in the type list, */
215 /* there can be at most */
216 /* */
217 /* (32768 - 28 - 10) / 12 = 2727 */
218 /* */
219 /* resources. */
220 /* */
221 /* A type list starts with a two-byte counter, followed by 10-byte */
222 /* type records. Assuming that there are no resources, the number of */
223 /* type records can be at most */
224 /* */
225 /* (32768 - 28 - 2) / 8 = 4079 */
226 /* */
227 if ( cnt > 4079 )
228 return FT_THROW( Invalid_Table );
229
230 for ( i = 0; i < cnt; i++ )
231 {
232 if ( FT_READ_LONG( tag_internal ) ||
233 FT_READ_SHORT( subcnt ) ||
234 FT_READ_SHORT( rpos ) )
235 return error;
236
237 FT_TRACE2(( "Resource tags: %c%c%c%c\n",
238 (char)( 0xFF & ( tag_internal >> 24 ) ),
239 (char)( 0xFF & ( tag_internal >> 16 ) ),
240 (char)( 0xFF & ( tag_internal >> 8 ) ),
241 (char)( 0xFF & ( tag_internal >> 0 ) ) ));
242 FT_TRACE3(( " : subcount=%d, suboffset=0x%04lx\n",
243 subcnt, rpos ));
244
245 if ( tag_internal == tag )
246 {
247 *count = subcnt + 1;
248 rpos += map_offset;
249
250 /* a zero count might be valid in the resource specification, */
251 /* however, it is completely useless to us */
252 if ( *count < 1 || *count > 2727 )
253 return FT_THROW( Invalid_Table );
254
256 if ( error )
257 return error;
258
259 if ( FT_NEW_ARRAY( ref, *count ) )
260 return error;
261
262 for ( j = 0; j < *count; j++ )
263 {
264 if ( FT_READ_SHORT( ref[j].res_id ) )
265 goto Exit;
266 if ( FT_STREAM_SKIP( 2 ) ) /* resource name offset */
267 goto Exit;
268 if ( FT_READ_LONG( temp ) ) /* attributes (8bit), offset (24bit) */
269 goto Exit;
270 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */
271 goto Exit;
272
273 /*
274 * According to Inside Macintosh: More Macintosh Toolbox,
275 * "Resource IDs" (1-46), there are some reserved IDs.
276 * However, FreeType2 is not a font synthesizer, no need
277 * to check the acceptable resource ID.
278 */
279 if ( temp < 0 )
280 {
281 error = FT_THROW( Invalid_Table );
282 goto Exit;
283 }
284
285 ref[j].offset = temp & 0xFFFFFFL;
286
287 FT_TRACE3(( " [%d]:"
288 " resource_id=0x%04x, offset=0x%08lx\n",
289 j, (FT_UShort)ref[j].res_id, ref[j].offset ));
290 }
291
292 if ( sort_by_res_id )
293 {
294 ft_qsort( ref,
295 (size_t)*count,
296 sizeof ( FT_RFork_Ref ),
297 ( int(*)(const void*,
298 const void*) )ft_raccess_sort_ref_by_id );
299
300 FT_TRACE3(( " -- sort resources by their ids --\n" ));
301
302 for ( j = 0; j < *count; j++ )
303 FT_TRACE3(( " [%d]:"
304 " resource_id=0x%04x, offset=0x%08lx\n",
305 j, ref[j].res_id, ref[j].offset ));
306 }
307
308 if ( FT_NEW_ARRAY( offsets_internal, *count ) )
309 goto Exit;
310
311 /* XXX: duplicated reference ID,
312 * gap between reference IDs are acceptable?
313 * further investigation on Apple implementation is needed.
314 */
315 for ( j = 0; j < *count; j++ )
316 offsets_internal[j] = rdata_pos + ref[j].offset;
317
318 *offsets = offsets_internal;
320
321 Exit:
322 FT_FREE( ref );
323 return error;
324 }
325 }
326
327 return FT_THROW( Cannot_Open_Resource );
328 }
FT_Library library
Definition: cffdrivr.c:660
#define NULL
Definition: types.h:112
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_TRACE3(varformat)
Definition: ftdebug.h:190
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_TRACE2(varformat)
Definition: ftdebug.h:189
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:341
#define FT_FREE(ptr)
Definition: ftmemory.h:337
static int ft_raccess_sort_ref_by_id(FT_RFork_Ref *a, FT_RFork_Ref *b)
Definition: ftrfork.c:171
#define ft_qsort
Definition: ftstdlib.h:122
#define FT_READ_LONG(var)
Definition: ftstream.h:342
#define FT_STREAM_SKIP(distance)
Definition: ftstream.h:529
FT_Stream_Seek(FT_Stream stream, FT_ULong pos)
Definition: ftstream.c:56
#define FT_READ_SHORT(var)
Definition: ftstream.h:338
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:299
signed long FT_Long
Definition: fttypes.h:242
unsigned short FT_UShort
Definition: fttypes.h:209
static const FxOffsetAndName offsets[]
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:122
static calc_node_t temp
Definition: rpn_ieee.c:38
static void Exit(void)
Definition: sock.c:1330
FT_Memory memory
Definition: ftobjs.h:895
Definition: send.c:48
Definition: parse.h:23
Definition: ecma_167.h:138
_In_ size_t cnt
Definition: wcstombs.cpp:43

◆ FT_Raccess_Get_HeaderInfo()

FT_Raccess_Get_HeaderInfo ( FT_Library  library,
FT_Stream  stream,
FT_Long  rfork_offset,
FT_Long map_offset,
FT_Long rdata_pos 
)

Definition at line 50 of file ftrfork.c.

55 {
57 unsigned char head[16], head2[16];
58 FT_Long map_pos, map_len, rdata_len;
59 int allzeros, allmatch, i;
60 FT_Long type_list;
61
63
64
65 error = FT_Stream_Seek( stream, (FT_ULong)rfork_offset );
66 if ( error )
67 return error;
68
70 if ( error )
71 return error;
72
73 /* ensure positive values */
74 if ( head[0] >= 0x80 ||
75 head[4] >= 0x80 ||
76 head[8] >= 0x80 ||
77 head[12] >= 0x80 )
78 return FT_THROW( Unknown_File_Format );
79
80 *rdata_pos = ( head[ 0] << 24 ) |
81 ( head[ 1] << 16 ) |
82 ( head[ 2] << 8 ) |
83 head[ 3];
84 map_pos = ( head[ 4] << 24 ) |
85 ( head[ 5] << 16 ) |
86 ( head[ 6] << 8 ) |
87 head[ 7];
88 rdata_len = ( head[ 8] << 24 ) |
89 ( head[ 9] << 16 ) |
90 ( head[10] << 8 ) |
91 head[11];
92 map_len = ( head[12] << 24 ) |
93 ( head[13] << 16 ) |
94 ( head[14] << 8 ) |
95 head[15];
96
97 /* the map must not be empty */
98 if ( !map_pos )
99 return FT_THROW( Unknown_File_Format );
100
101 /* check whether rdata and map overlap */
102 if ( *rdata_pos < map_pos )
103 {
104 if ( *rdata_pos > map_pos - rdata_len )
105 return FT_THROW( Unknown_File_Format );
106 }
107 else
108 {
109 if ( map_pos > *rdata_pos - map_len )
110 return FT_THROW( Unknown_File_Format );
111 }
112
113 /* check whether end of rdata or map exceeds stream size */
114 if ( FT_LONG_MAX - rdata_len < *rdata_pos ||
115 FT_LONG_MAX - map_len < map_pos ||
116
117 FT_LONG_MAX - ( *rdata_pos + rdata_len ) < rfork_offset ||
118 FT_LONG_MAX - ( map_pos + map_len ) < rfork_offset ||
119
120 (FT_ULong)( rfork_offset + *rdata_pos + rdata_len ) > stream->size ||
121 (FT_ULong)( rfork_offset + map_pos + map_len ) > stream->size )
122 return FT_THROW( Unknown_File_Format );
123
124 *rdata_pos += rfork_offset;
125 map_pos += rfork_offset;
126
127 error = FT_Stream_Seek( stream, (FT_ULong)map_pos );
128 if ( error )
129 return error;
130
131 head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */
132
133 error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
134 if ( error )
135 return error;
136
137 allzeros = 1;
138 allmatch = 1;
139 for ( i = 0; i < 16; i++ )
140 {
141 if ( head2[i] != 0 )
142 allzeros = 0;
143 if ( head2[i] != head[i] )
144 allmatch = 0;
145 }
146 if ( !allzeros && !allmatch )
147 return FT_THROW( Unknown_File_Format );
148
149 /* If we have reached this point then it is probably a mac resource */
150 /* file. Now, does it contain any interesting resources? */
151
152 (void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */
153 + 2 /* skip file resource number */
154 + 2 ); /* skip attributes */
155
156 if ( FT_READ_SHORT( type_list ) )
157 return error;
158 if ( type_list < 0 )
159 return FT_THROW( Unknown_File_Format );
160
161 error = FT_Stream_Seek( stream, (FT_ULong)( map_pos + type_list ) );
162 if ( error )
163 return error;
164
165 *map_offset = map_pos + type_list;
166 return FT_Err_Ok;
167 }
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define FT_LONG_MAX
Definition: ftstdlib.h:67
FT_Stream_Read(FT_Stream stream, FT_Byte *buffer, FT_ULong count)
Definition: ftstream.c:109
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_UNUSED(arg)
unsigned int size
Definition: parse.h:27

◆ FT_Raccess_Guess()

FT_Raccess_Guess ( FT_Library  library,
FT_Stream  stream,
char base_name,
char **  new_names,
FT_Long offsets,
FT_Error errors 
)

Definition at line 916 of file ftrfork.c.

922 {
923 FT_Int i;
924
926 FT_UNUSED( stream );
927 FT_UNUSED( base_name );
928
929
930 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
931 {
932 new_names[i] = NULL;
933 offsets[i] = 0;
934 errors[i] = FT_ERR( Unimplemented_Feature );
935 }
936 }
#define FT_RACCESS_N_RULES
Definition: ftrfork.h:36
#define FT_ERR(e)
Definition: fttypes.h:599
signed int FT_Int
Definition: fttypes.h:220

◆ ft_raccess_sort_ref_by_id()

static int ft_raccess_sort_ref_by_id ( FT_RFork_Ref a,
FT_RFork_Ref b 
)
static

Definition at line 171 of file ftrfork.c.

173 {
174 if ( a->res_id < b->res_id )
175 return -1;
176 else if ( a->res_id > b->res_id )
177 return 1;
178 else
179 return 0;
180 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by FT_Raccess_Get_DataOffsets().