diff options
author | David Fries <David@Fries.net> | 2016-04-13 23:32:46 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2016-04-14 14:35:42 +0200 |
commit | 85827fbb642463ab724a9471a7a88f93fa2a217d (patch) | |
tree | 76e24b1f30c6a0d2b80af8240af254a3c1160528 | |
parent | 96db90e98a6040f680f4ebca1880268a2e1ab6cc (diff) | |
download | alsa-utils-85827fbb642463ab724a9471a7a88f93fa2a217d.tar.gz |
aplay: fix lurking capture file overwrite bug
If -d was given to arecord while commit
8aa13eec80eac312e4b99423909387660fb99b8f (now reverted) was in effect,
the last read would be shorter than the chunk size, but pcm_read would
read and return the chunk size, the samples were discarded, and
capture() continued in a loop because count never reached 0. arecord
opens a new file each loop iteration, if arecord is dynamically naming
files, --use-strftime option or beyond the wave 2GB limit, this will
generate a series of header only wave files. If the file is unique
the originally recorded data is lost and it will continue overwriting
the same file with a header only wave file.
While the current pcm_read can't fail (it can exit), it is better to
just fix this lurking bug in case it is "fixed" again.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | aplay/aplay.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/aplay/aplay.c b/aplay/aplay.c index 7acaa83..2da7dda 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -3067,11 +3067,14 @@ static void capture(char *orig_name) size_t c = (rest <= (off64_t)chunk_bytes) ? (size_t)rest : chunk_bytes; size_t f = c * 8 / bits_per_frame; - if (pcm_read(audiobuf, f) != f) + if (pcm_read(audiobuf, f) != f) { + in_aborting = 1; break; + } if (write(fd, audiobuf, c) != c) { perror(name); - prg_exit(EXIT_FAILURE); + in_aborting = 1; + break; } count -= c; rest -= c; @@ -3091,7 +3094,7 @@ static void capture(char *orig_name) } if (in_aborting) - break; + prg_exit(EXIT_FAILURE); /* repeat the loop when format is raw without timelimit or * requested counts of data are recorded |