summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2021-05-29 12:54:22 +0100
committerTim-Philipp Müller <tim@centricular.com>2021-05-29 14:31:34 +0100
commitaa4448cdd6b59bce0c0bd925ca56901f58a572e2 (patch)
tree9ffef0b4a2649e9e125df791093f29313b4e0f78
parentf4049fc292ce1ed749701d2a31bf6026b7d60eac (diff)
rtpjpegpay: fix image corruption when compiled with MSVC on Windows
On Windows with MSVC, jpeg_header_size would end up 2 bytes larger than it should be. This then leads to the first 2 bytes of the actual jpeg image data to be dropped, because we think those belong to the header, which results in an undecodable image when reconstructed in the depayloader. What happens is that when the compiler evaluates jpeg_header_size = mem.offset + read_u16_and_inc_offset_by_2(&mem); it actually uses the mem.offset value after it has been increased by the function call on the right hand size of the equation. From section 6.5 of the C99 spec: 3. The grouping of operators and operands is indicated by the syntax [74]. Except as specified later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/889 Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/999>
-rw-r--r--gst/rtp/gstrtpjpegpay.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gst/rtp/gstrtpjpegpay.c b/gst/rtp/gstrtpjpegpay.c
index d2d6b9952..0e32e16fb 100644
--- a/gst/rtp/gstrtpjpegpay.c
+++ b/gst/rtp/gstrtpjpegpay.c
@@ -780,8 +780,9 @@ gst_rtp_jpeg_pay_handle_buffer (GstRTPBasePayload * basepayload,
case JPEG_MARKER_SOS:
sos_found = TRUE;
GST_LOG_OBJECT (pay, "SOS found");
- jpeg_header_size =
- memory.offset + parse_mem_inc_offset_guint16 (&memory);
+ jpeg_header_size = memory.offset;
+ /* Do not re-combine into single statement with previous line! */
+ jpeg_header_size += parse_mem_inc_offset_guint16 (&memory);
break;
case JPEG_MARKER_EOI:
GST_WARNING_OBJECT (pay, "EOI reached before SOS!");