| 1 |
#include "../meta.h" |
| 2 |
|
| 3 |
#include "support/util.h" |
| 4 |
|
| 5 |
table_meta *otfcc_readMeta(const otfcc_Packet packet, const otfcc_Options *options) { |
| 6 |
table_meta *meta = NULL; |
| 7 |
FOR_TABLE(OTFCC_CHR('m','e','t','a'), table) { |
| 8 |
if (table.length < 16) goto FAIL; |
| 9 |
uint32_t version = read_32u(table.data + 0); |
| 10 |
uint32_t flags = read_32u(table.data + 4); |
| 11 |
uint32_t dataMapsCount = read_32u(table.data + 12); |
| 12 |
if (table.length < 16 + 12 * dataMapsCount) goto FAIL; |
| 13 |
|
| 14 |
meta = table_iMeta.create(); |
| 15 |
meta->version = version; |
| 16 |
meta->flags = flags; |
| 17 |
|
| 18 |
for (uint32_t j = 0; j < dataMapsCount; j++) { |
| 19 |
uint32_t tag = read_32u(table.data + 16 + 12 * j + 0); |
| 20 |
uint32_t offset = read_32u(table.data + 16 + 12 * j + 4); |
| 21 |
uint32_t length = read_32u(table.data + 16 + 12 * j + 8); |
| 22 |
if (table.length < offset + length) continue; |
| 23 |
|
| 24 |
meta_iEntries.push( |
| 25 |
&meta->entries, |
| 26 |
(meta_Entry){.tag = tag, .data = sdsnewlen((char *)(table.data + offset), length)}); |
| 27 |
} |
| 28 |
return meta; |
| 29 |
|
| 30 |
FAIL: |
| 31 |
logWarning("Table 'meta' corrupted.\n"); |
| 32 |
table_iMeta.free(meta); |
| 33 |
meta = NULL; |
| 34 |
} |
| 35 |
return meta; |
| 36 |
} |