jpegdec: decode the correct number of lines for interlaced frames
authorMichael Olbrich <m.olbrich@pengutronix.de>
Mon, 31 Aug 2020 14:12:33 +0000 (16:12 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 26 May 2023 00:04:02 +0000 (01:04 +0100)
commitb4330c730b66d280d5e7403b9be0d651db12f62d
treec7da0133ae7c709111ba89871976d26cf7ab8a96
parentd93f0a51c224c435705c03b31fa50fb3b78d961e
jpegdec: decode the correct number of lines for interlaced frames

For interlaced jpeg, gst_jpeg_dec_decode_direct() is called twice, once for each
field. In this case, stride[n] is plane_stride[n] * 2 to ensure that only every
other line is written. So the loop must stop at height / num_fields.

If the frame is really interlaced then continuing beyound this, is not harmful,
because jpeg_read_raw_data() will do nothing and return 0, so am info message is
printed.

However, if the frame is not actually interlaced, just misdetected as interlaced
then there is still data available from the second half of the frame. Now
line[0][j] is set to the scratch buffer. If the scratch buffer is not allocated
(because the height is a multiple of v_samp[0] * DCTSIZE) then the result is a
segfault due to a null-pointer dereference.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4717>
subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c