mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 08:48:00 +02:00
Add test for error handling with broken PNG streams
Would-have-caught: https://bugs.freedesktop.org/show_bug.cgi?id=104325 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
82f4028532
commit
6b0593827b
2 changed files with 88 additions and 0 deletions
|
|
@ -87,6 +87,7 @@ test_sources = \
|
|||
copy-path.c \
|
||||
coverage.c \
|
||||
create-for-stream.c \
|
||||
create-from-broken-png-stream.c \
|
||||
create-from-png.c \
|
||||
create-from-png-stream.c \
|
||||
culled-glyphs.c \
|
||||
|
|
|
|||
87
test/create-from-broken-png-stream.c
Normal file
87
test/create-from-broken-png-stream.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright © 2017 Uli Schlachter
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software
|
||||
* and its documentation for any purpose is hereby granted without
|
||||
* fee, provided that the above copyright notice appear in all copies
|
||||
* and that both that copyright notice and this permission notice
|
||||
* appear in supporting documentation, and that the name of
|
||||
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
||||
* distribution of the software without specific, written prior
|
||||
* permission. Red Hat, Inc. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
||||
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Author: Uli Schlachter <psychon@znc.in>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static const unsigned char broken_png_data[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
||||
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
||||
0x08, 0x02, 0x00, 0x00, 0x00, 0xfd, 0xd4, 0x9a, 0xff, 0x00, 0x00, 0x00,
|
||||
};
|
||||
static const size_t broken_png_data_length
|
||||
= sizeof(broken_png_data) / sizeof(broken_png_data[0]);
|
||||
|
||||
static cairo_status_t
|
||||
read_png_from_data (void *closure, unsigned char *data, unsigned int length)
|
||||
{
|
||||
size_t *offset = closure;
|
||||
size_t remaining = broken_png_data_length - *offset;
|
||||
|
||||
if (remaining < length)
|
||||
return CAIRO_STATUS_READ_ERROR;
|
||||
|
||||
memcpy (data, &broken_png_data[*offset], length);
|
||||
*offset += length;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
preamble (cairo_test_context_t *ctx)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_status_t status;
|
||||
cairo_status_t expected;
|
||||
size_t offset = 0;
|
||||
|
||||
surface = cairo_image_surface_create_from_png_stream (read_png_from_data,
|
||||
&offset);
|
||||
|
||||
/* XXX: The actual error is CAIRO_STATUS_PNG_ERROR, but
|
||||
* _cairo_surface_create_in_error() does not support that.
|
||||
*/
|
||||
expected = CAIRO_STATUS_NO_MEMORY;
|
||||
status = cairo_surface_status (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
if (status != CAIRO_STATUS_NO_MEMORY) {
|
||||
cairo_test_log (ctx,
|
||||
"Error: expected error %s, but got %s\n",
|
||||
cairo_status_to_string (expected),
|
||||
cairo_status_to_string (status));
|
||||
|
||||
return CAIRO_TEST_FAILURE;
|
||||
}
|
||||
|
||||
return CAIRO_TEST_SUCCESS;
|
||||
}
|
||||
|
||||
CAIRO_TEST (create_from_broken_png_stream,
|
||||
"Tests the creation of a PNG from malformed data",
|
||||
"png", /* keywords */
|
||||
NULL, /* requirements */
|
||||
0, 0,
|
||||
preamble, NULL)
|
||||
Loading…
Add table
Reference in a new issue