| 1 |
/* |
| 2 |
* Test program, which tests negative strides in compositing with fence_malloc |
| 3 |
* to check for out-of-bounds memory access. |
| 4 |
*/ |
| 5 |
#include "utils.h" |
| 6 |
|
| 7 |
#if FENCE_MALLOC_ACTIVE |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <sys/mman.h> |
| 12 |
|
| 13 |
typedef struct |
| 14 |
{ |
| 15 |
int width; |
| 16 |
int height; |
| 17 |
int stride; |
| 18 |
pixman_format_code_t format; |
| 19 |
} image_info_t; |
| 20 |
|
| 21 |
typedef struct |
| 22 |
{ |
| 23 |
pixman_op_t op; |
| 24 |
|
| 25 |
image_info_t src; |
| 26 |
image_info_t dest; |
| 27 |
|
| 28 |
int src_x; |
| 29 |
int src_y; |
| 30 |
int dest_x; |
| 31 |
int dest_y; |
| 32 |
int width; |
| 33 |
int height; |
| 34 |
} composite_info_t; |
| 35 |
|
| 36 |
const composite_info_t info = |
| 37 |
{ |
| 38 |
PIXMAN_OP_SRC, |
| 39 |
{ 16, 1000, -16, PIXMAN_a8r8g8b8 }, |
| 40 |
{ 16, 1000, -16, PIXMAN_a8r8g8b8 }, |
| 41 |
0, 0, |
| 42 |
0, 0, |
| 43 |
16, 1000 |
| 44 |
}; |
| 45 |
|
| 46 |
static pixman_image_t * |
| 47 |
make_image (const image_info_t *info, char **buf) |
| 48 |
{ |
| 49 |
int size = info->height * abs (info->stride); |
| 50 |
char *data = fence_malloc (size); |
| 51 |
int i; |
| 52 |
|
| 53 |
for (i = 0; i < size; ++i) |
| 54 |
data[i] = (i % 255) ^ (((i % 16) << 4) | (i & 0xf0)); |
| 55 |
|
| 56 |
*buf = data; |
| 57 |
if (info->stride < 0) |
| 58 |
/* Move to the start of the last scanline. */ |
| 59 |
data += size + info->stride; |
| 60 |
|
| 61 |
return pixman_image_create_bits (info->format, |
| 62 |
info->width, |
| 63 |
info->height, |
| 64 |
(uint32_t *)data, |
| 65 |
info->stride); |
| 66 |
} |
| 67 |
|
| 68 |
static void |
| 69 |
test_composite (const composite_info_t *info) |
| 70 |
{ |
| 71 |
char *src_buf; |
| 72 |
char *dest_buf; |
| 73 |
pixman_image_t *src = make_image (&info->src, &src_buf); |
| 74 |
pixman_image_t *dest = make_image (&info->dest, &dest_buf); |
| 75 |
|
| 76 |
pixman_image_composite (PIXMAN_OP_SRC, src, NULL, dest, |
| 77 |
info->src_x, info->src_y, |
| 78 |
0, 0, |
| 79 |
info->dest_x, info->dest_y, |
| 80 |
info->width, info->height); |
| 81 |
|
| 82 |
fence_free (src_buf); |
| 83 |
fence_free (dest_buf); |
| 84 |
pixman_image_unref (src); |
| 85 |
pixman_image_unref (dest); |
| 86 |
} |
| 87 |
|
| 88 |
int |
| 89 |
main (int argc, char **argv) |
| 90 |
{ |
| 91 |
test_composite (&info); |
| 92 |
|
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
#else /* FENCE_MALLOC_ACTIVE */ |
| 97 |
|
| 98 |
int |
| 99 |
main (int argc, char **argv) |
| 100 |
{ |
| 101 |
/* Automake return code for test SKIP. */ |
| 102 |
return 77; |
| 103 |
} |
| 104 |
|
| 105 |
#endif /* FENCE_MALLOC_ACTIVE */ |