-
Notifications
You must be signed in to change notification settings - Fork 15
/
invalid-coverage.c
161 lines (127 loc) · 4.4 KB
/
invalid-coverage.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include "qcms.h"
typedef uint32_t __be32;
/* __builtin_bswap isn't available in older gccs
* so open code it for now */
static __be32 cpu_to_be32(int32_t v)
{
#ifdef LITTLE_ENDIAN
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24);
//return __builtin_bswap32(v);
#else
return v;
#endif
}
char *buf;
static void write_u32(size_t offset, uint32_t value)
{
*(__be32*)(buf + offset) = cpu_to_be32(value);
}
#if 0
static uint16_t read_u16(struct mem_source *mem, size_t offset)
{
if (offset + 2 > mem->size) {
invalid_source(mem, "Invalid offset");
return 0;
} else {
return be16_to_cpu(*(__be16*)(mem->buf + offset));
}
}
#endif
static void write_u8(size_t offset, uint8_t value)
{
*(uint8_t*)(buf + offset) = value;
}
int main()
{
qcms_profile_release(qcms_profile_sRGB());
buf = calloc(1500, 1);
assert(!qcms_profile_from_memory(buf, 1500));
// invalid size
write_u32(0, 2500);
assert(!qcms_profile_from_memory(buf, 1500));
// proper size
write_u32(0, 1500);
assert(!qcms_profile_from_memory(buf, 1500));
#define INPUT_DEVICE_PROFILE 0x73636e72 // 'scnr'
write_u32(12, INPUT_DEVICE_PROFILE);
assert(!qcms_profile_from_memory(buf, 1500));
write_u8(8, 0x3); // invalid major revision
assert(!qcms_profile_from_memory(buf, 1500));
write_u8(8, 0x2); // major revision
write_u8(9, 0x55); // invalid minor revision
assert(!qcms_profile_from_memory(buf, 1500));
write_u8(8, 0x2); // major revision
write_u8(9, 0x40); // minor revision
write_u8(10, 1); // reserved 1
write_u8(11, 0); // reserved 2
assert(!qcms_profile_from_memory(buf, 1500));
write_u8(10, 0); // reserved 1
write_u8(64, 0x32); // invalid rendering intent
assert(!qcms_profile_from_memory(buf, 1500));
write_u8(64, 0); // invalid rendering intent
#define RGB_SIGNATURE 0x52474220
#define GRAY_SIGNATURE 0x47524159
write_u32(16, RGB_SIGNATURE);
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128, 15000); // tag count
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128, 15); // tag count
assert(!qcms_profile_from_memory(buf, 1500));
#define TAG_bXYZ 0x6258595a
#define TAG_gXYZ 0x6758595a
#define TAG_rXYZ 0x7258595a
#define TAG_rTRC 0x72545243
#define TAG_bTRC 0x62545243
#define TAG_gTRC 0x67545243
#define TAG_kTRC 0x6b545243
#define TAG_A2B0 0x41324230
write_u32(128 + 4, TAG_rXYZ); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4, 1000); // offset
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*1*3, TAG_gXYZ); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*1*3 + 4, 1000); // offset
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*2*3, TAG_bXYZ); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*2*3 + 4, 1000); // offset
assert(!qcms_profile_from_memory(buf, 1500));
#define XYZ_TYPE 0x58595a20 // 'XYZ '
#define CURVE_TYPE 0x63757276 // 'curv'
#define LUT16_TYPE 0x6d667432 // 'mft2'
#define LUT8_TYPE 0x6d667431 // 'mft1'
write_u32(1000, XYZ_TYPE);
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*3*3, TAG_rTRC); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*3*3 + 4, 1100); // offset
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*4*3, TAG_gTRC); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*4*3 + 4, 1100); // offset
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*5*3, TAG_bTRC); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*5*3 + 4, 1100); // offset
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(1100, CURVE_TYPE);
qcms_profile_release(qcms_profile_from_memory(buf, 1500));
write_u32(1108, 100000); // curve count
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(1108, 1); // curve count
qcms_profile_release(qcms_profile_from_memory(buf, 1500));
/* test out gray profiles */
write_u32(16, GRAY_SIGNATURE);
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*6*3, TAG_kTRC); // tag
assert(!qcms_profile_from_memory(buf, 1500));
write_u32(128 + 4 + 4*6*3 + 4, 1100); // offset
qcms_profile_release(qcms_profile_from_memory(buf, 1500));
/* test out profiles that are the wrong size */
qcms_profile_from_path("sample-trunc.icc");
return 0;
}