Skip to content

Commit 3a83181

Browse files
committed
pikvm/pikvm#1558: Discard JPEGs with invalid headers
1 parent 913cdac commit 3a83181

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libs/capture.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,12 @@ bool _capture_is_buffer_valid(const us_capture_s *cap, const struct v4l2_buffer
573573
return false;
574574
}
575575

576+
const u16 begin_marker = (((u16)(data[0]) << 8) | data[1]);
577+
if (begin_marker != 0xFFD8) {
578+
_LOG_DEBUG("Discarding JPEG frame with invalid header: begin_marker=0x%04x, bytesused=%u", begin_marker, buf->bytesused);
579+
return false;
580+
}
581+
576582
const u8 *const end_ptr = data + buf->bytesused;
577583
const u8 *const eoi_ptr = end_ptr - 2;
578584
const u16 eoi_marker = (((u16)(eoi_ptr[0]) << 8) | eoi_ptr[1]);

0 commit comments

Comments
 (0)