aboutsummaryrefslogtreecommitdiffstats
path: root/libparsepcf_get_property_subtable.c
blob: 5da1f5676d1e13fd7f3456e3f8d6fbbd0934137c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libparsepcf_get_property_subtable(const void *file, size_t size,
                                  const struct libparsepcf_table *table,
                                  const struct libparsepcf_properties *meta,
                                  struct libparsepcf_property_subtable *props,
                                  size_t first, size_t count)
{
	const char *text = file;
	int msb = table->format & LIBPARSEPCF_BYTE;
	size_t pos = table->offset + 8 + first * 9;
	size_t i, off, maxlen;

	(void) size;

	for (i = 0; i < count; i++, pos += 9) {
		off = (size_t)PARSE_UINT32(&text[pos + 0], msb);
		if (off > meta->strings_size)
			goto ebfont;
		maxlen = meta->strings_size - off;
		props[i].name = &meta->strings[off];
		if (!memchr(props[i].name, 0, maxlen))
			goto ebfont;

		props[i].is_string_property = !!text[pos + 4];

		if (props[i].is_string_property) {
			off = (size_t)PARSE_UINT32(&text[pos + 5], msb);
			if (off > meta->strings_size)
				goto ebfont;
			maxlen = meta->strings_size - off;
			props[i].value.string_value = &meta->strings[off];
			if (!memchr(props[i].value.string_value, 0, maxlen))
				goto ebfont;
		} else {
			props[i].value.signed_value = PARSE_INT32(&text[pos + 5], msb);
		}
	}

	return 0;

ebfont:
	errno = EBFONT;
	return -1;
}