114b11b2bSmrg/* 214b11b2bSmrg * Test program, which tests negative strides in compositing with fence_malloc 314b11b2bSmrg * to check for out-of-bounds memory access. 414b11b2bSmrg */ 514b11b2bSmrg#include "utils.h" 614b11b2bSmrg 714b11b2bSmrg#if FENCE_MALLOC_ACTIVE 814b11b2bSmrg 914b11b2bSmrg#include <stdio.h> 1014b11b2bSmrg#include <stdlib.h> 1114b11b2bSmrg#include <sys/mman.h> 1214b11b2bSmrg 1314b11b2bSmrgtypedef struct 1414b11b2bSmrg{ 1514b11b2bSmrg int width; 1614b11b2bSmrg int height; 1714b11b2bSmrg int stride; 1814b11b2bSmrg pixman_format_code_t format; 1914b11b2bSmrg} image_info_t; 2014b11b2bSmrg 2114b11b2bSmrgtypedef struct 2214b11b2bSmrg{ 2314b11b2bSmrg pixman_op_t op; 2414b11b2bSmrg 2514b11b2bSmrg image_info_t src; 2614b11b2bSmrg image_info_t dest; 2714b11b2bSmrg 2814b11b2bSmrg int src_x; 2914b11b2bSmrg int src_y; 3014b11b2bSmrg int dest_x; 3114b11b2bSmrg int dest_y; 3214b11b2bSmrg int width; 3314b11b2bSmrg int height; 3414b11b2bSmrg} composite_info_t; 3514b11b2bSmrg 3614b11b2bSmrgconst composite_info_t info = 3714b11b2bSmrg{ 3814b11b2bSmrg PIXMAN_OP_SRC, 3914b11b2bSmrg { 16, 1000, -16, PIXMAN_a8r8g8b8 }, 4014b11b2bSmrg { 16, 1000, -16, PIXMAN_a8r8g8b8 }, 4114b11b2bSmrg 0, 0, 4214b11b2bSmrg 0, 0, 4314b11b2bSmrg 16, 1000 4414b11b2bSmrg}; 4514b11b2bSmrg 4614b11b2bSmrgstatic pixman_image_t * 4714b11b2bSmrgmake_image (const image_info_t *info, char **buf) 4814b11b2bSmrg{ 4914b11b2bSmrg int size = info->height * abs (info->stride); 5014b11b2bSmrg char *data = fence_malloc (size); 5114b11b2bSmrg int i; 5214b11b2bSmrg 5314b11b2bSmrg for (i = 0; i < size; ++i) 5414b11b2bSmrg data[i] = (i % 255) ^ (((i % 16) << 4) | (i & 0xf0)); 5514b11b2bSmrg 5614b11b2bSmrg *buf = data; 5714b11b2bSmrg if (info->stride < 0) 5814b11b2bSmrg /* Move to the start of the last scanline. */ 5914b11b2bSmrg data += size + info->stride; 6014b11b2bSmrg 6114b11b2bSmrg return pixman_image_create_bits (info->format, 6214b11b2bSmrg info->width, 6314b11b2bSmrg info->height, 6414b11b2bSmrg (uint32_t *)data, 6514b11b2bSmrg info->stride); 6614b11b2bSmrg} 6714b11b2bSmrg 6814b11b2bSmrgstatic void 6914b11b2bSmrgtest_composite (const composite_info_t *info) 7014b11b2bSmrg{ 7114b11b2bSmrg char *src_buf; 7214b11b2bSmrg char *dest_buf; 7314b11b2bSmrg pixman_image_t *src = make_image (&info->src, &src_buf); 7414b11b2bSmrg pixman_image_t *dest = make_image (&info->dest, &dest_buf); 7514b11b2bSmrg 7614b11b2bSmrg pixman_image_composite (PIXMAN_OP_SRC, src, NULL, dest, 7714b11b2bSmrg info->src_x, info->src_y, 7814b11b2bSmrg 0, 0, 7914b11b2bSmrg info->dest_x, info->dest_y, 8014b11b2bSmrg info->width, info->height); 8114b11b2bSmrg 8214b11b2bSmrg fence_free (src_buf); 8314b11b2bSmrg fence_free (dest_buf); 8414b11b2bSmrg pixman_image_unref (src); 8514b11b2bSmrg pixman_image_unref (dest); 8614b11b2bSmrg} 8714b11b2bSmrg 8814b11b2bSmrgint 8914b11b2bSmrgmain (int argc, char **argv) 9014b11b2bSmrg{ 9114b11b2bSmrg test_composite (&info); 9214b11b2bSmrg 9314b11b2bSmrg return 0; 9414b11b2bSmrg} 9514b11b2bSmrg 9614b11b2bSmrg#else /* FENCE_MALLOC_ACTIVE */ 9714b11b2bSmrg 9814b11b2bSmrgint 9914b11b2bSmrgmain (int argc, char **argv) 10014b11b2bSmrg{ 10114b11b2bSmrg /* Automake return code for test SKIP. */ 10214b11b2bSmrg return 77; 10314b11b2bSmrg} 10414b11b2bSmrg 10514b11b2bSmrg#endif /* FENCE_MALLOC_ACTIVE */ 106