otlcommn.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /***************************************************************************/
  2. /* */
  3. /* otlcommn.c */
  4. /* */
  5. /* OpenType layout support, common tables (body). */
  6. /* */
  7. /* Copyright 2002 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #include "otlayout.h"
  18. /*************************************************************************/
  19. /*************************************************************************/
  20. /***** *****/
  21. /***** COVERAGE TABLE *****/
  22. /***** *****/
  23. /*************************************************************************/
  24. /*************************************************************************/
  25. OTL_LOCALDEF( void )
  26. otl_coverage_validate( OTL_Bytes table,
  27. OTL_Validator valid )
  28. {
  29. OTL_Bytes p;
  30. OTL_UInt format;
  31. if ( table + 4 > valid->limit )
  32. OTL_INVALID_TOO_SHORT;
  33. format = OTL_NEXT_USHORT( p );
  34. switch ( format )
  35. {
  36. case 1:
  37. {
  38. OTL_UInt count = OTL_NEXT_USHORT( p );
  39. if ( p + count * 2 >= valid->limit )
  40. OTL_INVALID_TOO_SHORT;
  41. /* XXX: check glyph indices */
  42. }
  43. break;
  44. case 2:
  45. {
  46. OTL_UInt n, num_ranges = OTL_NEXT_USHORT( p );
  47. OTL_UInt start, end, start_cover, total = 0, last = 0;
  48. if ( p + num_ranges * 6 >= valid->limit )
  49. OTL_INVALID_TOO_SHORT;
  50. for ( n = 0; n < num_ranges; n++ )
  51. {
  52. start = OTL_NEXT_USHORT( p );
  53. end = OTL_NEXT_USHORT( p );
  54. start_cover = OTL_NEXT_USHORT( p );
  55. if ( start > end || start_cover != total )
  56. OTL_INVALID_DATA;
  57. if ( n > 0 && start <= last )
  58. OTL_INVALID_DATA;
  59. total += end - start + 1;
  60. last = end;
  61. }
  62. }
  63. break;
  64. default:
  65. OTL_INVALID_FORMAT;
  66. }
  67. }
  68. OTL_LOCALDEF( OTL_UInt )
  69. otl_coverage_get_count( OTL_Bytes table )
  70. {
  71. OTL_Bytes p = table;
  72. OTL_UInt format = OTL_NEXT_USHORT( p );
  73. OTL_UInt count = OTL_NEXT_USHORT( p );
  74. OTL_UInt result = 0;
  75. switch ( format )
  76. {
  77. case 1:
  78. return count;
  79. case 2:
  80. {
  81. OTL_UInt start, end;
  82. for ( ; count > 0; count-- )
  83. {
  84. start = OTL_NEXT_USHORT( p );
  85. end = OTL_NEXT_USHORT( p );
  86. p += 2; /* skip start_index */
  87. result += end - start + 1;
  88. }
  89. }
  90. break;
  91. default:
  92. ;
  93. }
  94. return result;
  95. }
  96. OTL_LOCALDEF( OTL_Int )
  97. otl_coverage_get_index( OTL_Bytes table,
  98. OTL_UInt glyph_index )
  99. {
  100. OTL_Bytes p = table;
  101. OTL_UInt format = OTL_NEXT_USHORT( p );
  102. OTL_UInt count = OTL_NEXT_USHORT( p );
  103. switch ( format )
  104. {
  105. case 1:
  106. {
  107. OTL_UInt min = 0, max = count, mid, gindex;
  108. table += 4;
  109. while ( min < max )
  110. {
  111. mid = ( min + max ) >> 1;
  112. p = table + 2 * mid;
  113. gindex = OTL_PEEK_USHORT( p );
  114. if ( glyph_index == gindex )
  115. return (OTL_Int)mid;
  116. if ( glyph_index < gindex )
  117. max = mid;
  118. else
  119. min = mid + 1;
  120. }
  121. }
  122. break;
  123. case 2:
  124. {
  125. OTL_UInt min = 0, max = count, mid;
  126. OTL_UInt start, end, delta, start_cover;
  127. table += 4;
  128. while ( min < max )
  129. {
  130. mid = ( min + max ) >> 1;
  131. p = table + 6 * mid;
  132. start = OTL_NEXT_USHORT( p );
  133. end = OTL_NEXT_USHORT( p );
  134. if ( glyph_index < start )
  135. max = mid;
  136. else if ( glyph_index > end )
  137. min = mid + 1;
  138. else
  139. return (OTL_Int)( glyph_index + OTL_NEXT_USHORT( p ) - start );
  140. }
  141. }
  142. break;
  143. default:
  144. ;
  145. }
  146. return -1;
  147. }
  148. /*************************************************************************/
  149. /*************************************************************************/
  150. /***** *****/
  151. /***** CLASS DEFINITION TABLE *****/
  152. /***** *****/
  153. /*************************************************************************/
  154. /*************************************************************************/
  155. OTL_LOCALDEF( void )
  156. otl_class_definition_validate( OTL_Bytes table,
  157. OTL_Validator valid )
  158. {
  159. OTL_Bytes p = table;
  160. OTL_UInt format;
  161. if ( p + 4 > valid->limit )
  162. OTL_INVALID_TOO_SHORT;
  163. format = OTL_NEXT_USHORT( p );
  164. switch ( format )
  165. {
  166. case 1:
  167. {
  168. OTL_UInt count, start = OTL_NEXT_USHORT( p );
  169. if ( p + 2 > valid->limit )
  170. OTL_INVALID_TOO_SHORT;
  171. count = OTL_NEXT_USHORT( p );
  172. if ( p + count * 2 > valid->limit )
  173. OTL_INVALID_TOO_SHORT;
  174. /* XXX: check glyph indices */
  175. }
  176. break;
  177. case 2:
  178. {
  179. OTL_UInt n, num_ranges = OTL_NEXT_USHORT( p );
  180. OTL_UInt start, end, value, last = 0;
  181. if ( p + num_ranges * 6 > valid->limit )
  182. OTL_INVALID_TOO_SHORT;
  183. for ( n = 0; n < num_ranges; n++ )
  184. {
  185. start = OTL_NEXT_USHORT( p );
  186. end = OTL_NEXT_USHORT( p );
  187. value = OTL_NEXT_USHORT( p ); /* ignored */
  188. if ( start > end || ( n > 0 && start <= last ) )
  189. OTL_INVALID_DATA;
  190. last = end;
  191. }
  192. }
  193. break;
  194. default:
  195. OTL_INVALID_FORMAT;
  196. }
  197. }
  198. OTL_LOCALDEF( OTL_UInt )
  199. otl_class_definition_get_value( OTL_Bytes table,
  200. OTL_UInt glyph_index )
  201. {
  202. OTL_Bytes p = table;
  203. OTL_UInt format = OTL_NEXT_USHORT( p );
  204. switch ( format )
  205. {
  206. case 1:
  207. {
  208. OTL_UInt start = OTL_NEXT_USHORT( p );
  209. OTL_UInt count = OTL_NEXT_USHORT( p );
  210. OTL_UInt idx = (OTL_UInt)( glyph_index - start );
  211. if ( idx < count )
  212. {
  213. p += 2 * idx;
  214. return OTL_PEEK_USHORT( p );
  215. }
  216. }
  217. break;
  218. case 2:
  219. {
  220. OTL_UInt count = OTL_NEXT_USHORT( p );
  221. OTL_UInt min = 0, max = count, mid, gindex;
  222. table += 4;
  223. while ( min < max )
  224. {
  225. mid = ( min + max ) >> 1;
  226. p = table + 6 * mid;
  227. start = OTL_NEXT_USHORT( p );
  228. end = OTL_NEXT_USHORT( p );
  229. if ( glyph_index < start )
  230. max = mid;
  231. else if ( glyph_index > end )
  232. min = mid + 1;
  233. else
  234. return OTL_PEEK_USHORT( p );
  235. }
  236. }
  237. break;
  238. default:
  239. ;
  240. }
  241. return 0;
  242. }
  243. /*************************************************************************/
  244. /*************************************************************************/
  245. /***** *****/
  246. /***** DEVICE TABLE *****/
  247. /***** *****/
  248. /*************************************************************************/
  249. /*************************************************************************/
  250. OTL_LOCALDEF( void )
  251. otl_device_table_validate( OTL_Bytes table,
  252. OTL_Validator valid )
  253. {
  254. OTL_Bytes p = table;
  255. OTL_UInt start, end, count, format, count;
  256. if ( p + 8 > valid->limit )
  257. OTL_INVALID_TOO_SHORT;
  258. start = OTL_NEXT_USHORT( p );
  259. end = OTL_NEXT_USHORT( p );
  260. format = OTL_NEXT_USHORT( p );
  261. if ( format < 1 || format > 3 || end < start )
  262. OTL_INVALID_DATA;
  263. count = (OTL_UInt)( end - start + 1 );
  264. if ( p + ( ( 1 << format ) * count ) / 8 > valid->limit )
  265. OTL_INVALID_TOO_SHORT;
  266. }
  267. OTL_LOCALDEF( OTL_UInt )
  268. otl_device_table_get_start( OTL_Bytes table )
  269. {
  270. OTL_Bytes p = table;
  271. return OTL_PEEK_USHORT( p );
  272. }
  273. OTL_LOCALDEF( OTL_UInt )
  274. otl_device_table_get_end( OTL_Bytes table )
  275. {
  276. OTL_Bytes p = table + 2;
  277. return OTL_PEEK_USHORT( p );
  278. }
  279. OTL_LOCALDEF( OTL_Int )
  280. otl_device_table_get_delta( OTL_Bytes table,
  281. OTL_UInt size )
  282. {
  283. OTL_Bytes p = table;
  284. OTL_Int result = 0;
  285. OTL_UInt start, end, format, idx, value;
  286. start = OTL_NEXT_USHORT( p );
  287. end = OTL_NEXT_USHORT( p );
  288. format = OTL_NEXT_USHORT( p );
  289. if ( size >= start && size <= end )
  290. {
  291. /* we could do that with clever bit operations, but a switch is */
  292. /* much simpler to understand and maintain */
  293. /* */
  294. switch ( format )
  295. {
  296. case 1:
  297. idx = (OTL_UInt)( ( size - start ) * 2 );
  298. p += idx / 16;
  299. value = OTL_PEEK_USHORT( p );
  300. shift = idx & 15;
  301. result = (OTL_Short)( value << shift ) >> ( 14 - shift );
  302. break;
  303. case 2:
  304. idx = (OTL_UInt)( ( size - start ) * 4 );
  305. p += idx / 16;
  306. value = OTL_PEEK_USHORT( p );
  307. shift = idx & 15;
  308. result = (OTL_Short)( value << shift ) >> ( 12 - shift );
  309. break;
  310. case 3:
  311. idx = (OTL_UInt)( ( size - start ) * 8 );
  312. p += idx / 16;
  313. value = OTL_PEEK_USHORT( p );
  314. shift = idx & 15;
  315. result = (OTL_Short)( value << shift ) >> ( 8 - shift );
  316. break;
  317. default:
  318. ;
  319. }
  320. }
  321. return result;
  322. }
  323. /*************************************************************************/
  324. /*************************************************************************/
  325. /***** *****/
  326. /***** LOOKUP LISTS *****/
  327. /***** *****/
  328. /*************************************************************************/
  329. /*************************************************************************/
  330. OTL_LOCALDEF( void )
  331. otl_lookup_validate( OTL_Bytes table,
  332. OTL_Validator valid )
  333. {
  334. OTL_Bytes p = table;
  335. OTL_UInt num_tables;
  336. if ( table + 6 > valid->limit )
  337. OTL_INVALID_TOO_SHORT;
  338. p += 4;
  339. num_tables = OTL_NEXT_USHORT( p );
  340. if ( p + num_tables * 2 > valid->limit )
  341. OTL_INVALID_TOO_SHORT;
  342. for ( ; num_tables > 0; num_tables-- )
  343. {
  344. offset = OTL_NEXT_USHORT( p );
  345. if ( table + offset >= valid->limit )
  346. OTL_INVALID_OFFSET;
  347. }
  348. /* XXX: check sub-tables? */
  349. }
  350. OTL_LOCALDEF( OTL_UInt )
  351. otl_lookup_get_count( OTL_Bytes table )
  352. {
  353. OTL_Bytes p = table + 4;
  354. return OTL_PEEK_USHORT( p );
  355. }
  356. OTL_LOCALDEF( OTL_Bytes )
  357. otl_lookup_get_table( OTL_Bytes table,
  358. OTL_UInt idx )
  359. {
  360. OTL_Bytes p, result = NULL;
  361. OTL_UInt count;
  362. p = table + 4;
  363. count = OTL_NEXT_USHORT( p );
  364. if ( idx < count )
  365. {
  366. p += idx * 2;
  367. result = table + OTL_PEEK_USHORT( p );
  368. }
  369. return result;
  370. }
  371. /*************************************************************************/
  372. /*************************************************************************/
  373. /***** *****/
  374. /***** LOOKUP LISTS *****/
  375. /***** *****/
  376. /*************************************************************************/
  377. /*************************************************************************/
  378. OTL_LOCALDEF( void )
  379. otl_lookup_list_validate( OTL_Bytes table,
  380. OTL_Validator valid )
  381. {
  382. OTL_Bytes p = table, q;
  383. OTL_UInt num_lookups, offset;
  384. if ( p + 2 > valid->limit )
  385. OTL_INVALID_TOO_SHORT;
  386. num_lookups = OTL_NEXT_USHORT( p );
  387. if ( p + num_lookups * 2 > valid->limit )
  388. OTL_INVALID_TOO_SHORT;
  389. for ( ; num_lookups > 0; num_lookups-- )
  390. {
  391. offset = OTL_NEXT_USHORT( p );
  392. otl_lookup_validate( table + offset, valid );
  393. }
  394. }
  395. OTL_LOCALDEF( OTL_UInt )
  396. otl_lookup_list_get_count( OTL_Bytes table )
  397. {
  398. OTL_Bytes p = table;
  399. return OTL_PEEK_USHORT( p );
  400. }
  401. OTL_LOCALDEF( OTL_Bytes )
  402. otl_lookup_list_get_lookup( OTL_Bytes table,
  403. OTL_UInt idx )
  404. {
  405. OTL_Bytes p, result = 0;
  406. OTL_UInt count;
  407. p = table;
  408. count = OTL_NEXT_USHORT( p );
  409. if ( idx < count )
  410. {
  411. p += idx * 2;
  412. result = table + OTL_PEEK_USHORT( p );
  413. }
  414. return result;
  415. }
  416. OTL_LOCALDEF( OTL_Bytes )
  417. otl_lookup_list_get_table( OTL_Bytes table,
  418. OTL_UInt lookup_index,
  419. OTL_UInt table_index )
  420. {
  421. OTL_Bytes result = NULL;
  422. result = otl_lookup_list_get_lookup( table, lookup_index );
  423. if ( result )
  424. result = otl_lookup_get_table( result, table_index );
  425. return result;
  426. }
  427. OTL_LOCALDEF( void )
  428. otl_lookup_list_foreach( OTL_Bytes table,
  429. OTL_ForeachFunc func,
  430. OTL_Pointer func_data )
  431. {
  432. OTL_Bytes p = table;
  433. OTL_UInt count = OTL_NEXT_USHORT( p );
  434. for ( ; count > 0; count-- )
  435. func( table + OTL_NEXT_USHORT( p ), func_data );
  436. }
  437. /*************************************************************************/
  438. /*************************************************************************/
  439. /***** *****/
  440. /***** FEATURES *****/
  441. /***** *****/
  442. /*************************************************************************/
  443. /*************************************************************************/
  444. OTL_LOCALDEF( void )
  445. otl_feature_validate( OTL_Bytes table,
  446. OTL_Validator valid )
  447. {
  448. OTL_Bytes p = table;
  449. OTL_UInt feat_params, num_lookups;
  450. if ( p + 4 > valid->limit )
  451. OTL_INVALID_TOO_SHORT;
  452. feat_params = OTL_NEXT_USHORT( p ); /* ignored */
  453. num_lookups = OTL_NEXT_USHORT( p );
  454. if ( p + num_lookups * 2 > valid->limit )
  455. OTL_INVALID_TOO_SHORT;
  456. /* XXX: check lookup indices */
  457. }
  458. OTL_LOCALDEF( OTL_UInt )
  459. otl_feature_get_count( OTL_Bytes table )
  460. {
  461. OTL_Bytes p = table + 4;
  462. return OTL_PEEK_USHORT( p );
  463. }
  464. OTL_LOCALDEF( OTL_UInt )
  465. otl_feature_get_lookups( OTL_Bytes table,
  466. OTL_UInt start,
  467. OTL_UInt count,
  468. OTL_UInt *lookups )
  469. {
  470. OTL_Bytes p;
  471. OTL_UInt num_features, result = 0;
  472. p = table + 4;
  473. num_features = OTL_NEXT_USHORT( p );
  474. p += start * 2;
  475. for ( ; count > 0 && start < num_features; count--, start++ )
  476. {
  477. lookups[0] = OTL_NEXT_USHORT(p);
  478. lookups++;
  479. result++;
  480. }
  481. return result;
  482. }
  483. /*************************************************************************/
  484. /*************************************************************************/
  485. /***** *****/
  486. /***** FEATURE LIST *****/
  487. /***** *****/
  488. /*************************************************************************/
  489. /*************************************************************************/
  490. OTL_LOCALDEF( void )
  491. otl_feature_list_validate( OTL_Bytes table,
  492. OTL_Validator valid )
  493. {
  494. OTL_Bytes p = table;
  495. OTL_UInt num_features, offset;
  496. if ( table + 2 > valid->limit )
  497. OTL_INVALID_TOO_SHORT;
  498. num_features = OTL_NEXT_USHORT( p );
  499. if ( p + num_features * 2 > valid->limit )
  500. OTL_INVALID_TOO_SHORT;
  501. for ( ; num_features > 0; num_features-- )
  502. {
  503. p += 4; /* skip tag */
  504. offset = OTL_NEXT_USHORT( p );
  505. otl_feature_table_validate( table + offset, valid );
  506. }
  507. }
  508. OTL_LOCALDEF( OTL_UInt )
  509. otl_feature_list_get_count( OTL_Bytes table )
  510. {
  511. OTL_Bytes p = table;
  512. return OTL_PEEK_USHORT( p );
  513. }
  514. OTL_LOCALDEF( OTL_Bytes )
  515. otl_feature_list_get_feature( OTL_Bytes table,
  516. OTL_UInt idx )
  517. {
  518. OTL_Bytes p, result = NULL;
  519. OTL_UInt count;
  520. p = table;
  521. count = OTL_NEXT_USHORT( p );
  522. if ( idx < count )
  523. {
  524. p += idx * 2;
  525. result = table + OTL_PEEK_USHORT( p );
  526. }
  527. return result;
  528. }
  529. OTL_LOCALDEF( void )
  530. otl_feature_list_foreach( OTL_Bytes table,
  531. OTL_ForeachFunc func,
  532. OTL_Pointer func_data )
  533. {
  534. OTL_Bytes p;
  535. OTL_UInt count;
  536. p = table;
  537. count = OTL_NEXT_USHORT( p );
  538. for ( ; count > 0; count-- )
  539. func( table + OTL_NEXT_USHORT( p ), func_data );
  540. }
  541. /*************************************************************************/
  542. /*************************************************************************/
  543. /***** *****/
  544. /***** LANGUAGE SYSTEM *****/
  545. /***** *****/
  546. /*************************************************************************/
  547. /*************************************************************************/
  548. OTL_LOCALDEF( void )
  549. otl_lang_validate( OTL_Bytes table,
  550. OTL_Validator valid )
  551. {
  552. OTL_Bytes p = table;
  553. OTL_UInt lookup_order;
  554. OTL_UInt req_feature;
  555. OTL_UInt num_features;
  556. if ( table + 6 >= valid->limit )
  557. OTL_INVALID_TOO_SHORT;
  558. lookup_order = OTL_NEXT_USHORT( p );
  559. req_feature = OTL_NEXT_USHORT( p );
  560. num_features = OTL_NEXT_USHORT( p );
  561. /* XXX: check req_feature if not 0xFFFFU */
  562. if ( p + 2 * num_features >= valid->limit )
  563. OTL_INVALID_TOO_SHORT;
  564. /* XXX: check features indices! */
  565. }
  566. OTL_LOCALDEF( OTL_UInt )
  567. otl_lang_get_count( OTL_Bytes table )
  568. {
  569. OTL_Bytes p = table + 4;
  570. return OTL_PEEK_USHORT( p );
  571. }
  572. OTL_LOCALDEF( OTL_UInt )
  573. otl_lang_get_req_feature( OTL_Bytes table )
  574. {
  575. OTL_Bytes p = table + 2;
  576. return OTL_PEEK_USHORT( p );
  577. }
  578. OTL_LOCALDEF( OTL_UInt )
  579. otl_lang_get_features( OTL_Bytes table,
  580. OTL_UInt start,
  581. OTL_UInt count,
  582. OTL_UInt *features )
  583. {
  584. OTL_Bytes p = table + 4;
  585. OTL_UInt num_features = OTL_NEXT_USHORT( p );
  586. OTL_UInt result = 0;
  587. p += start * 2;
  588. for ( ; count > 0 && start < num_features; start++, count-- )
  589. {
  590. features[0] = OTL_NEXT_USHORT( p );
  591. features++;
  592. result++;
  593. }
  594. return result;
  595. }
  596. /*************************************************************************/
  597. /*************************************************************************/
  598. /***** *****/
  599. /***** SCRIPTS *****/
  600. /***** *****/
  601. /*************************************************************************/
  602. /*************************************************************************/
  603. OTL_LOCALDEF( void )
  604. otl_script_validate( OTL_Bytes table,
  605. OTL_Validator valid )
  606. {
  607. OTL_UInt default_lang;
  608. OTL_Bytes p = table;
  609. if ( table + 4 > valid->limit )
  610. OTL_INVALID_TOO_SHORT;
  611. default_lang = OTL_NEXT_USHORT( p );
  612. num_langs = OTL_NEXT_USHORT( p );
  613. if ( default_lang != 0 )
  614. {
  615. if ( table + default_lang >= valid->limit )
  616. OTL_INVALID_OFFSET;
  617. }
  618. if ( p + num_langs * 6 >= valid->limit )
  619. OTL_INVALID_OFFSET;
  620. for ( ; num_langs > 0; num_langs-- )
  621. {
  622. OTL_UInt offset;
  623. p += 4; /* skip tag */
  624. offset = OTL_NEXT_USHORT( p );
  625. otl_lang_validate( table + offset, valid );
  626. }
  627. }
  628. OTL_LOCALDEF( void )
  629. otl_script_list_validate( OTL_Bytes list,
  630. OTL_Validator valid )
  631. {
  632. OTL_UInt num_scripts;
  633. OTL_Bytes p = list;
  634. if ( list + 2 > valid->limit )
  635. OTL_INVALID_TOO_SHORT;
  636. num_scripts = OTL_NEXT_USHORT( p );
  637. if ( p + num_scripts * 6 > valid->limit )
  638. OTL_INVALID_TOO_SHORT;
  639. for ( ; num_scripts > 0; num_scripts-- )
  640. {
  641. OTL_UInt offset;
  642. p += 4; /* skip tag */
  643. offset = OTL_NEXT_USHORT( p );
  644. otl_script_table_validate( list + offset, valid );
  645. }
  646. }
  647. /*************************************************************************/
  648. /*************************************************************************/
  649. /***** *****/
  650. /***** LOOKUP LISTS *****/
  651. /***** *****/
  652. /*************************************************************************/
  653. /*************************************************************************/
  654. static void
  655. otl_lookup_table_validate( OTL_Bytes table,
  656. OTL_UInt type_count,
  657. OTL_ValidateFunc* type_funcs,
  658. OTL_Validator valid )
  659. {
  660. OTL_Bytes p = table;
  661. OTL_UInt lookup_type, lookup_flag, count;
  662. OTL_ValidateFunc validate;
  663. OTL_CHECK( 6 );
  664. lookup_type = OTL_NEXT_USHORT( p );
  665. lookup_flag = OTL_NEXT_USHORT( p );
  666. count = OTL_NEXT_USHORT( p );
  667. if ( lookup_type == 0 || lookup_type >= type_count )
  668. OTL_INVALID_DATA;
  669. validate = type_funcs[ lookup_type - 1 ];
  670. OTL_CHECK( 2*count );
  671. for ( ; count > 0; count-- )
  672. validate( table + OTL_NEXT_USHORT( p ), valid );
  673. }
  674. OTL_LOCALDEF( void )
  675. otl_lookup_list_validate( OTL_Bytes table,
  676. OTL_UInt type_count,
  677. OTL_ValidateFunc* type_funcs,
  678. OTL_Validator valid )
  679. {
  680. OTL_Bytes p = table;
  681. OTL_UInt count;
  682. OTL_CHECK( 2 );
  683. count = OTL_NEXT_USHORT( p );
  684. OTL_CHECK( 2*count );
  685. for ( ; count > 0; count-- )
  686. otl_lookup_table_validate( table + OTL_NEXT_USHORT( p ),
  687. type_count, type_funcs, valid );
  688. }
  689. /* END */