diff options
author | Jaroslav Kysela <perex@perex.cz> | 2020-10-13 19:28:29 +0200 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2020-10-13 19:31:49 +0200 |
commit | a6c8ac0c85ca1b16684a687c7000c73aa38b7776 (patch) | |
tree | a1484afc5983c6f834cc234d72317e5991eaffdb | |
parent | aa89ad93623fc97fed6f99370a97c9c3eee1d6fd (diff) | |
download | alsa-lib-a6c8ac0c85ca1b16684a687c7000c73aa38b7776.tar.gz |
pcm: meter / s16 - add protection for the maximum copied frames
The rewind or forward may cause the stream pointer change. Although
this patch does not fix the real meter update issue, it breaks
the possible big loops when the stream pointers are desynced with
the meters. It does not make sense to copy more samples than the
pcm buffer contains.
Link: https://lore.kernel.org/alsa-devel/f56d6a67-014a-e562-c253-830c0ec03717@ivitera.com/
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | src/pcm/pcm_meter.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c index 20b41876..2dcf8e45 100644 --- a/src/pcm/pcm_meter.c +++ b/src/pcm/pcm_meter.c @@ -79,6 +79,8 @@ static void snd_pcm_meter_add_frames(snd_pcm_t *pcm, snd_pcm_uframes_t frames) { snd_pcm_meter_t *meter = pcm->private_data; + if (frames > pcm->buffer_size) + frames = pcm->buffer_size; while (frames > 0) { snd_pcm_uframes_t n = frames; snd_pcm_uframes_t dst_offset = ptr % meter->buf_size; @@ -1100,6 +1102,8 @@ static void s16_update(snd_pcm_scope_t *scope) size = meter->now - s16->old; if (size < 0) size += spcm->boundary; + if (size > (snd_pcm_sframes_t)s16->pcm->buffer_size) + size = s16->pcm->buffer_size; offset = s16->old % meter->buf_size; while (size > 0) { snd_pcm_uframes_t frames = size; |