otlgdef.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #include "otlgdef.h"
  2. #include "otlcommn.h"
  3. /************************************************************************/
  4. /************************************************************************/
  5. /***** *****/
  6. /***** ATTACHMENTS LIST *****/
  7. /***** *****/
  8. /************************************************************************/
  9. /************************************************************************/
  10. static void
  11. otl_attach_point_validate( OTL_Bytes table,
  12. OTL_Validator valid )
  13. {
  14. OTL_Bytes p = table;
  15. OTL_UInt count;
  16. if ( p + 2 > valid->limit )
  17. OTL_INVALID_TOO_SHORT;
  18. count = OTL_NEXT_USHORT( p );
  19. if ( table + count*2 > valid->limit )
  20. OTL_INVALID_TOO_SHORT;
  21. }
  22. static void
  23. otl_attach_list_validate( OTL_Bytes table,
  24. OTL_Validator valid )
  25. {
  26. OTL_Bytes p = table;
  27. OTL_Bytes coverage;
  28. OTL_UInt count;
  29. if ( p + 4 > valid->limit )
  30. OTL_INVALID_TOO_SHORT;
  31. coverage = table + OTL_NEXT_USHORT( p );
  32. count = OTL_NEXT_USHORT( p );
  33. otl_coverage_validate( coverage, valid );
  34. if ( count != otl_coverage_get_count( coverage ) )
  35. OTL_INVALID_DATA;
  36. if ( p + count*2 > valid->limit )
  37. OTL_INVALID_TOO_SHORT;
  38. for ( ; count > 0; count-- )
  39. otl_attach_point_validate( table + OTL_NEXT_USHORT( p ) );
  40. }
  41. /************************************************************************/
  42. /************************************************************************/
  43. /***** *****/
  44. /***** LIGATURE CARETS *****/
  45. /***** *****/
  46. /************************************************************************/
  47. /************************************************************************/
  48. static void
  49. otl_caret_value_validate( OTL_Bytes table,
  50. OTL_Validator valid )
  51. {
  52. OTL_Bytes p = table;
  53. if ( p + 4 > valid->limit )
  54. OTL_INVALID_TOO_SHORT;
  55. format = OTL_NEXT_USHORT( p );
  56. switch ( format )
  57. {
  58. case 1:
  59. case 2:
  60. break;
  61. case 3:
  62. {
  63. OTL_Bytes device;
  64. p += 2;
  65. if ( p + 2 > valid->limit )
  66. OTL_INVALID_TOO_SHORT;
  67. otl_device_table_validate( table + OTL_PEEK_USHORT( p ) );
  68. }
  69. break;
  70. default:
  71. OTL_INVALID_DATA;
  72. }
  73. }
  74. static void
  75. otl_ligature_glyph_validate( OTL_Bytes table,
  76. OTL_Validator valid )
  77. {
  78. OTL_Bytes p = table;
  79. OTL_UInt count;
  80. if ( p + 2 > valid->limit )
  81. OTL_INVALID_TOO_SHORT;
  82. count = OTL_NEXT_USHORT( p );
  83. if ( p + count*2 > valid->limit )
  84. OTL_INVALID_TOO_SHORT;
  85. for ( ; count > 0; count-- )
  86. otl_caret_value_validate( table + OTL_NEXT_USHORT( p ) );
  87. }
  88. static void
  89. otl_ligature_caret_list_validate( OTL_Bytes table,
  90. OTL_Validator valid )
  91. {
  92. OTL_Bytes p = table;
  93. OTL_Bytes coverage;
  94. OTL_UInt count;
  95. if ( p + 4 > valid->limit )
  96. OTL_INVALID_TOO_SHORT;
  97. coverage = table + OTL_NEXT_USHORT( p );
  98. count = OTL_NEXT_USHORT( p );
  99. otl_coverage_validate( coverage, valid );
  100. if ( count != otl_coverage_get_count( coverage ) )
  101. OTL_INVALID_DATA;
  102. if ( p + count*2 > valid->limit )
  103. OTL_INVALID_TOO_SHORT;
  104. for ( ; count > 0; count-- )
  105. otl_ligature_glyph_validate( table + OTL_NEXT_USHORT( p ) );
  106. }
  107. /************************************************************************/
  108. /************************************************************************/
  109. /***** *****/
  110. /***** GDEF TABLE *****/
  111. /***** *****/
  112. /************************************************************************/
  113. /************************************************************************/
  114. OTL_APIDEF( void )
  115. otl_gdef_validate( OTL_Bytes table,
  116. OTL_Validator valid )
  117. {
  118. OTL_Bytes p = table;
  119. if ( p + 12 > valid->limit )
  120. OTL_INVALID_TOO_SHORT;
  121. /* check format */
  122. if ( OTL_NEXT_ULONG( p ) != 0x00010000UL )
  123. OTL_INVALID_FORMAT;
  124. /* validate class definition table */
  125. otl_class_definition_validate( table + OTL_NEXT_USHORT( p ) );
  126. /* validate attachment point list */
  127. otl_attach_list_validate( table + OTL_NEXT_USHORT( p ) );
  128. /* validate ligature caret list */
  129. otl_ligature_caret_list_validate( table + OTL_NEXT_USHORT( p ) );
  130. /* validate mark attach class */
  131. otl_class_definition_validate( table + OTL_NEXT_USHORT( p ) );
  132. }