[image] Check create_for_data() to ensure a valid minimum stride.

Double check that the user is not being silly by passing in a stride that
is too small for the width. evince/poppler is one such example...
This commit is contained in:
Chris Wilson 2008-10-28 09:59:01 +00:00
parent 88f628b397
commit 9481d999df

View file

@ -484,6 +484,7 @@ cairo_image_surface_create_for_data (unsigned char *data,
int stride)
{
pixman_format_code_t pixman_format;
int minstride;
if (! CAIRO_FORMAT_VALID (format))
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
@ -491,6 +492,17 @@ cairo_image_surface_create_for_data (unsigned char *data,
if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0)
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
minstride = cairo_format_stride_for_width (format, width);
if (stride < 0) {
if (stride > -minstride) {
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
}
} else {
if (stride < minstride) {
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
}
}
pixman_format = _cairo_format_to_pixman_format_code (format);
return _cairo_image_surface_create_with_pixman_format (data, pixman_format,