History

libavdevice/v4l2: fix invalid access to struct v4l2_buffer

In case we are short of queued buffers, at first v4l2_buffer was enqueued to kernel so it's not owned by user-space anymore. After that it's timestamp field was read, but it might be overwritten by driver at that moment. It resulted in invalid timestamp sometimes.

Jaroslav Beran committed 9 years ago

Commit 00a1e131 parent 5a941551 file · +4 −1Browse files

Unified · Split

libavdevice/v4l2.c+4−1
@@ -492,6 +492,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) · 491 unmodified lines
492492 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
493493 .memory = V4L2_MEMORY_MMAP
494494 };
495+ struct timeval buf_ts;
495496 int res;
496497
497498 pkt->size = 0;
@@ -508,6 +509,8 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) · 10 unmodified lines
508509 return res;
509510 }
510511
512+ buf_ts = buf.timestamp;
513+
511514 if (buf.index >= s->buffers) {
512515 av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n");
513516 return AVERROR(EINVAL);
@@ -583,7 +586,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) · 69 unmodified lines
583586 return AVERROR(ENOMEM);
584587 }
585588 }
586− pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
589+ pkt->pts = buf_ts.tv_sec * INT64_C(1000000) + buf_ts.tv_usec;
587590 convert_timestamp(ctx, &pkt->pts);
588591
589592 return pkt->size;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t