| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* ftrfork.c */ | 3 /* ftrfork.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* Embedded resource forks accessor (body). */ | 5 /* Embedded resource forks accessor (body). */ |
| 6 /* */ | 6 /* */ |
| 7 /* Copyright 2004-2010, 2013, 2014 by */ | 7 /* Copyright 2004-2015 by */ |
| 8 /* Masatake YAMATO and Redhat K.K. */ | 8 /* Masatake YAMATO and Redhat K.K. */ |
| 9 /* */ | 9 /* */ |
| 10 /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ | 10 /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ |
| 11 /* derived from ftobjs.c. */ | 11 /* derived from ftobjs.c. */ |
| 12 /* */ | 12 /* */ |
| 13 /* This file is part of the FreeType project, and may only be used, */ | 13 /* This file is part of the FreeType project, and may only be used, */ |
| 14 /* modified, and distributed under the terms of the FreeType project */ | 14 /* modified, and distributed under the terms of the FreeType project */ |
| 15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 16 /* this file you indicate that you have read the license and */ | 16 /* this file you indicate that you have read the license and */ |
| 17 /* understand and accept it fully. */ | 17 /* understand and accept it fully. */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 { | 56 { |
| 57 FT_Error error; | 57 FT_Error error; |
| 58 unsigned char head[16], head2[16]; | 58 unsigned char head[16], head2[16]; |
| 59 FT_Long map_pos, rdata_len; | 59 FT_Long map_pos, rdata_len; |
| 60 int allzeros, allmatch, i; | 60 int allzeros, allmatch, i; |
| 61 FT_Long type_list; | 61 FT_Long type_list; |
| 62 | 62 |
| 63 FT_UNUSED( library ); | 63 FT_UNUSED( library ); |
| 64 | 64 |
| 65 | 65 |
| 66 error = FT_Stream_Seek( stream, rfork_offset ); | 66 error = FT_Stream_Seek( stream, (FT_ULong)rfork_offset ); |
| 67 if ( error ) | 67 if ( error ) |
| 68 return error; | 68 return error; |
| 69 | 69 |
| 70 error = FT_Stream_Read( stream, (FT_Byte *)head, 16 ); | 70 error = FT_Stream_Read( stream, (FT_Byte *)head, 16 ); |
| 71 if ( error ) | 71 if ( error ) |
| 72 return error; | 72 return error; |
| 73 | 73 |
| 74 *rdata_pos = rfork_offset + ( ( head[0] << 24 ) | | 74 /* ensure positive values */ |
| 75 ( head[1] << 16 ) | | 75 if ( head[0] >= 0x80 || head[4] >= 0x80 || head[8] >= 0x80 ) |
| 76 ( head[2] << 8 ) | | 76 return FT_THROW( Unknown_File_Format ); |
| 77 head[3] ); | 77 |
| 78 map_pos = rfork_offset + ( ( head[4] << 24 ) | | 78 *rdata_pos = ( head[ 0] << 24 ) | |
| 79 ( head[5] << 16 ) | | 79 ( head[ 1] << 16 ) | |
| 80 ( head[6] << 8 ) | | 80 ( head[ 2] << 8 ) | |
| 81 head[7] ); | 81 head[ 3]; |
| 82 rdata_len = ( head[ 8] << 24 ) | | 82 map_pos = ( head[ 4] << 24 ) | |
| 83 ( head[ 9] << 16 ) | | 83 ( head[ 5] << 16 ) | |
| 84 ( head[10] << 8 ) | | 84 ( head[ 6] << 8 ) | |
| 85 head[11]; | 85 head[ 7]; |
| 86 rdata_len = ( head[ 8] << 24 ) | |
| 87 ( head[ 9] << 16 ) | |
| 88 ( head[10] << 8 ) | |
| 89 head[11]; |
| 86 | 90 |
| 87 /* map_len = head[12] .. head[15] */ | 91 /* map_len = head[12] .. head[15] */ |
| 88 | 92 |
| 89 if ( *rdata_pos + rdata_len != map_pos || map_pos == rfork_offset ) | 93 if ( *rdata_pos != map_pos - rdata_len || map_pos == 0 ) |
| 90 return FT_THROW( Unknown_File_Format ); | 94 return FT_THROW( Unknown_File_Format ); |
| 91 | 95 |
| 92 error = FT_Stream_Seek( stream, map_pos ); | 96 if ( FT_LONG_MAX - rfork_offset < *rdata_pos || |
| 97 FT_LONG_MAX - rfork_offset < map_pos ) |
| 98 return FT_THROW( Unknown_File_Format ); |
| 99 |
| 100 *rdata_pos += rfork_offset; |
| 101 map_pos += rfork_offset; |
| 102 |
| 103 error = FT_Stream_Seek( stream, (FT_ULong)map_pos ); |
| 93 if ( error ) | 104 if ( error ) |
| 94 return error; | 105 return error; |
| 95 | 106 |
| 96 head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */ | 107 head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */ |
| 97 | 108 |
| 98 error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 ); | 109 error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 ); |
| 99 if ( error ) | 110 if ( error ) |
| 100 return error; | 111 return error; |
| 101 | 112 |
| 102 allzeros = 1; | 113 allzeros = 1; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 117 /* attributes. */ | 128 /* attributes. */ |
| 118 (void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */ | 129 (void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */ |
| 119 + 2 /* skip file resource number */ | 130 + 2 /* skip file resource number */ |
| 120 + 2 ); /* skip attributes */ | 131 + 2 ); /* skip attributes */ |
| 121 | 132 |
| 122 if ( FT_READ_USHORT( type_list ) ) | 133 if ( FT_READ_USHORT( type_list ) ) |
| 123 return error; | 134 return error; |
| 124 if ( type_list == -1 ) | 135 if ( type_list == -1 ) |
| 125 return FT_THROW( Unknown_File_Format ); | 136 return FT_THROW( Unknown_File_Format ); |
| 126 | 137 |
| 127 error = FT_Stream_Seek( stream, map_pos + type_list ); | 138 error = FT_Stream_Seek( stream, (FT_ULong)( map_pos + type_list ) ); |
| 128 if ( error ) | 139 if ( error ) |
| 129 return error; | 140 return error; |
| 130 | 141 |
| 131 *map_offset = map_pos + type_list; | 142 *map_offset = map_pos + type_list; |
| 132 return FT_Err_Ok; | 143 return FT_Err_Ok; |
| 133 } | 144 } |
| 134 | 145 |
| 135 | 146 |
| 136 static int | 147 static int |
| 137 ft_raccess_sort_ref_by_id( FT_RFork_Ref* a, | 148 ft_raccess_sort_ref_by_id( FT_RFork_Ref* a, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 159 FT_Error error; | 170 FT_Error error; |
| 160 int i, j, cnt, subcnt; | 171 int i, j, cnt, subcnt; |
| 161 FT_Long tag_internal, rpos; | 172 FT_Long tag_internal, rpos; |
| 162 FT_Memory memory = library->memory; | 173 FT_Memory memory = library->memory; |
| 163 FT_Long temp; | 174 FT_Long temp; |
| 164 FT_Long *offsets_internal = NULL; | 175 FT_Long *offsets_internal = NULL; |
| 165 FT_RFork_Ref *ref = NULL; | 176 FT_RFork_Ref *ref = NULL; |
| 166 | 177 |
| 167 | 178 |
| 168 FT_TRACE3(( "\n" )); | 179 FT_TRACE3(( "\n" )); |
| 169 error = FT_Stream_Seek( stream, map_offset ); | 180 error = FT_Stream_Seek( stream, (FT_ULong)map_offset ); |
| 170 if ( error ) | 181 if ( error ) |
| 171 return error; | 182 return error; |
| 172 | 183 |
| 173 if ( FT_READ_USHORT( cnt ) ) | 184 if ( FT_READ_USHORT( cnt ) ) |
| 174 return error; | 185 return error; |
| 175 cnt++; | 186 cnt++; |
| 176 | 187 |
| 177 for ( i = 0; i < cnt; ++i ) | 188 for ( i = 0; i < cnt; ++i ) |
| 178 { | 189 { |
| 179 if ( FT_READ_LONG( tag_internal ) || | 190 if ( FT_READ_LONG( tag_internal ) || |
| 180 FT_READ_USHORT( subcnt ) || | 191 FT_READ_USHORT( subcnt ) || |
| 181 FT_READ_USHORT( rpos ) ) | 192 FT_READ_USHORT( rpos ) ) |
| 182 return error; | 193 return error; |
| 183 | 194 |
| 184 FT_TRACE2(( "Resource tags: %c%c%c%c\n", | 195 FT_TRACE2(( "Resource tags: %c%c%c%c\n", |
| 185 (char)( 0xff & ( tag_internal >> 24 ) ), | 196 (char)( 0xFF & ( tag_internal >> 24 ) ), |
| 186 (char)( 0xff & ( tag_internal >> 16 ) ), | 197 (char)( 0xFF & ( tag_internal >> 16 ) ), |
| 187 (char)( 0xff & ( tag_internal >> 8 ) ), | 198 (char)( 0xFF & ( tag_internal >> 8 ) ), |
| 188 (char)( 0xff & ( tag_internal >> 0 ) ) )); | 199 (char)( 0xFF & ( tag_internal >> 0 ) ) )); |
| 189 FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n", | 200 FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n", |
| 190 subcnt, rpos )); | 201 subcnt, rpos )); |
| 191 | 202 |
| 192 if ( tag_internal == tag ) | 203 if ( tag_internal == tag ) |
| 193 { | 204 { |
| 194 *count = subcnt + 1; | 205 *count = subcnt + 1; |
| 195 rpos += map_offset; | 206 rpos += map_offset; |
| 196 | 207 |
| 197 error = FT_Stream_Seek( stream, rpos ); | 208 error = FT_Stream_Seek( stream, (FT_ULong)rpos ); |
| 198 if ( error ) | 209 if ( error ) |
| 199 return error; | 210 return error; |
| 200 | 211 |
| 201 if ( FT_NEW_ARRAY( ref, *count ) ) | 212 if ( FT_NEW_ARRAY( ref, *count ) ) |
| 202 return error; | 213 return error; |
| 203 | 214 |
| 204 for ( j = 0; j < *count; ++j ) | 215 for ( j = 0; j < *count; ++j ) |
| 205 { | 216 { |
| 206 if ( FT_READ_USHORT( ref[j].res_id ) ) | 217 if ( FT_READ_USHORT( ref[j].res_id ) ) |
| 207 goto Exit; | 218 goto Exit; |
| 208 if ( FT_STREAM_SKIP( 2 ) ) /* resource name */ | 219 if ( FT_STREAM_SKIP( 2 ) ) /* resource name */ |
| 209 goto Exit; | 220 goto Exit; |
| 210 if ( FT_READ_LONG( temp ) ) | 221 if ( FT_READ_LONG( temp ) ) |
| 211 goto Exit; | 222 goto Exit; |
| 212 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ | 223 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ |
| 213 goto Exit; | 224 goto Exit; |
| 214 | 225 |
| 215 ref[j].offset = temp & 0xFFFFFFL; | 226 ref[j].offset = temp & 0xFFFFFFL; |
| 216 FT_TRACE3(( " [%d]:" | 227 FT_TRACE3(( " [%d]:" |
| 217 " resource_id=0x%04x, offset=0x%08x\n", | 228 " resource_id=0x%04x, offset=0x%08x\n", |
| 218 j, ref[j].res_id, ref[j].offset )); | 229 j, ref[j].res_id, ref[j].offset )); |
| 219 } | 230 } |
| 220 | 231 |
| 221 if (sort_by_res_id) | 232 if (sort_by_res_id) |
| 222 { | 233 { |
| 223 ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), | 234 ft_qsort( ref, (size_t)*count, sizeof ( FT_RFork_Ref ), |
| 224 ( int(*)(const void*, const void*) ) | 235 ( int(*)(const void*, const void*) ) |
| 225 ft_raccess_sort_ref_by_id ); | 236 ft_raccess_sort_ref_by_id ); |
| 226 | 237 |
| 227 FT_TRACE3(( " -- sort resources by their ids --\n" )); | 238 FT_TRACE3(( " -- sort resources by their ids --\n" )); |
| 228 for ( j = 0; j < *count; ++ j ) { | 239 for ( j = 0; j < *count; ++ j ) { |
| 229 FT_TRACE3(( " [%d]:" | 240 FT_TRACE3(( " [%d]:" |
| 230 " resource_id=0x%04x, offset=0x%08x\n", | 241 " resource_id=0x%04x, offset=0x%08x\n", |
| 231 j, ref[j].res_id, ref[j].offset )); | 242 j, ref[j].res_id, ref[j].offset )); |
| 232 } | 243 } |
| 233 } | 244 } |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 char *base_file_name, | 717 char *base_file_name, |
| 707 FT_Int32 magic, | 718 FT_Int32 magic, |
| 708 FT_Long *result_offset ) | 719 FT_Long *result_offset ) |
| 709 { | 720 { |
| 710 FT_Int32 magic_from_stream; | 721 FT_Int32 magic_from_stream; |
| 711 FT_Error error; | 722 FT_Error error; |
| 712 FT_Int32 version_number = 0; | 723 FT_Int32 version_number = 0; |
| 713 FT_UShort n_of_entries; | 724 FT_UShort n_of_entries; |
| 714 | 725 |
| 715 int i; | 726 int i; |
| 716 FT_UInt32 entry_id, entry_offset, entry_length = 0; | 727 FT_Int32 entry_id, entry_offset, entry_length = 0; |
| 717 | 728 |
| 718 const FT_UInt32 resource_fork_entry_id = 0x2; | 729 const FT_Int32 resource_fork_entry_id = 0x2; |
| 719 | 730 |
| 720 FT_UNUSED( library ); | 731 FT_UNUSED( library ); |
| 721 FT_UNUSED( base_file_name ); | 732 FT_UNUSED( base_file_name ); |
| 722 FT_UNUSED( version_number ); | 733 FT_UNUSED( version_number ); |
| 723 FT_UNUSED( entry_length ); | 734 FT_UNUSED( entry_length ); |
| 724 | 735 |
| 725 | 736 |
| 726 if ( FT_READ_LONG( magic_from_stream ) ) | 737 if ( FT_READ_LONG( magic_from_stream ) ) |
| 727 return error; | 738 return error; |
| 728 if ( magic_from_stream != magic ) | 739 if ( magic_from_stream != magic ) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 FT_UNUSED( error ); | 817 FT_UNUSED( error ); |
| 807 | 818 |
| 808 | 819 |
| 809 new_length = ft_strlen( original_name ) + ft_strlen( insertion ); | 820 new_length = ft_strlen( original_name ) + ft_strlen( insertion ); |
| 810 if ( FT_ALLOC( new_name, new_length + 1 ) ) | 821 if ( FT_ALLOC( new_name, new_length + 1 ) ) |
| 811 return NULL; | 822 return NULL; |
| 812 | 823 |
| 813 tmp = ft_strrchr( original_name, '/' ); | 824 tmp = ft_strrchr( original_name, '/' ); |
| 814 if ( tmp ) | 825 if ( tmp ) |
| 815 { | 826 { |
| 816 ft_strncpy( new_name, original_name, tmp - original_name + 1 ); | 827 ft_strncpy( new_name, |
| 828 original_name, |
| 829 (size_t)( tmp - original_name + 1 ) ); |
| 817 new_name[tmp - original_name + 1] = '\0'; | 830 new_name[tmp - original_name + 1] = '\0'; |
| 818 slash = tmp + 1; | 831 slash = tmp + 1; |
| 819 } | 832 } |
| 820 else | 833 else |
| 821 { | 834 { |
| 822 slash = original_name; | 835 slash = original_name; |
| 823 new_name[0] = '\0'; | 836 new_name[0] = '\0'; |
| 824 } | 837 } |
| 825 | 838 |
| 826 ft_strcat( new_name, insertion ); | 839 ft_strcat( new_name, insertion ); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 offsets[i] = 0; | 871 offsets[i] = 0; |
| 859 errors[i] = FT_ERR( Unimplemented_Feature ); | 872 errors[i] = FT_ERR( Unimplemented_Feature ); |
| 860 } | 873 } |
| 861 } | 874 } |
| 862 | 875 |
| 863 | 876 |
| 864 #endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ | 877 #endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ |
| 865 | 878 |
| 866 | 879 |
| 867 /* END */ | 880 /* END */ |
| OLD | NEW |