jpegparse: fix incorrect reading of transform in app14 marker

"adobe" in app14 marker seem not a null-terminted string. so, when
we use gst_byte_reader_get_string_utf8, more bytes will be read until
null. and "gst_byte_reader_get_uint8 (&reader, &transform)" will almost fail
to read transform

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7356>
This commit is contained in:
Qian Hu (胡骞) 2024-08-14 19:44:40 +08:00 committed by GStreamer Marge Bot
parent 2b52b07a2f
commit 2447cf1077

View file

@ -625,8 +625,11 @@ static gboolean
gst_jpeg_parse_app14 (GstJpegParse * parse, GstJpegSegment * seg) gst_jpeg_parse_app14 (GstJpegParse * parse, GstJpegSegment * seg)
{ {
GstByteReader reader; GstByteReader reader;
const gchar *id_str;
guint8 transform; guint8 transform;
const guint8 *id = NULL;
const guint8 adobe_tag[] = {
'A', 'd', 'o', 'b', 'e'
};
if (seg->size < 6) /* less than 6 means no id string */ if (seg->size < 6) /* less than 6 means no id string */
return FALSE; return FALSE;
@ -634,11 +637,14 @@ gst_jpeg_parse_app14 (GstJpegParse * parse, GstJpegSegment * seg)
gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size); gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size);
gst_byte_reader_skip_unchecked (&reader, 2); gst_byte_reader_skip_unchecked (&reader, 2);
if (!gst_byte_reader_get_string_utf8 (&reader, &id_str)) if (!gst_byte_reader_peek_data (&reader, 5, &id))
return FALSE; return FALSE;
if (!g_str_has_prefix (id_str, "Adobe")) { if (G_LIKELY (!memcmp (id, adobe_tag, 5))) {
GST_DEBUG_OBJECT (parse, "Unhandled app14: %s", id_str); if (!gst_byte_reader_skip (&reader, 5))
return FALSE;
} else {
GST_DEBUG_OBJECT (parse, "Unhandled app14");
return TRUE; return TRUE;
} }