From f4a95058c70d829624146abd64b9b04d59dbc286 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 25 Dec 2012 13:55:09 +0100 Subject: vo_corevideo: correct stride usage The code assumed mp_image_alloc() would allocate an image large enough for corevideo's stride, which doesn't have to be the case. If corevideo's stride was larger than the stride of mp_image, the memcpy() would write beyond the mp_image allocation. This probably didn't actually happen, but fix the code to be more correct anyway. --- video/out/vo_corevideo.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'video') diff --git a/video/out/vo_corevideo.m b/video/out/vo_corevideo.m index 292dfea5a5..8c4b021e20 100644 --- a/video/out/vo_corevideo.m +++ b/video/out/vo_corevideo.m @@ -367,14 +367,15 @@ static mp_image_t *get_screenshot(struct vo *vo) size_t width = CVPixelBufferGetWidth(p->pixelBuffer); size_t height = CVPixelBufferGetHeight(p->pixelBuffer); size_t stride = CVPixelBufferGetBytesPerRow(p->pixelBuffer); - size_t image_size = stride * height; - mp_image_t *image = alloc_mpi(width, height, img_fmt); - memcpy(image->planes[0], base, image_size); - image->stride[0] = stride; + struct mp_image img = {0}; + mp_image_setfmt(&img, img_fmt); + mp_image_set_size(&img, width, height); + img.planes[0] = base; + img.stride[0] = stride; + struct mp_image *image = mp_image_new_copy(&img); mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh); - mp_image_set_colorspace_details(image, &p->colorspace); return image; -- cgit v1.2.3