Skip to content

Commit ccbea17

Browse files
mrabule1mchehab
authored andcommitted
media: Quit parsing stream if doesn't start with SOI
In the case we get an invalid stream, such as from v4l2-compliance streaming test, jpeg_next_marker will end up parsing the entire stream. The standard describes the high level syntax of a jpeg as starting with SOI, ending with EOI, so return error if the very first 2 bytes are not SOI. Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent b8035f7 commit ccbea17

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/media/v4l2-core/v4l2-jpeg.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,8 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
503503
out->num_dht = 0;
504504
out->num_dqt = 0;
505505

506-
/* the first marker must be SOI */
507-
marker = jpeg_next_marker(&stream);
508-
if (marker < 0)
509-
return marker;
510-
if (marker != SOI)
506+
/* the first bytes must be SOI, B.2.1 High-level syntax */
507+
if (jpeg_get_word_be(&stream) != SOI)
511508
return -EINVAL;
512509

513510
/* init value to signal if this marker is not present */

0 commit comments

Comments
 (0)