aplay: fix lurking capture file overwrite bug
PATCH 1/1 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.
---
In my case I wanted to record for 16 hours, I did get the audio, but I also found I had 3.1 million 44 byte files, which took the system 3 hours to unlink, I'm glad I at least discovered this problem the next day.. Debian has the effectively broken pcm_read, after figuring out what was going wrong, and that the current arecord doesn't exhibit the problem I wanted to fix it anyway. There are remaining problems, pcm_read will read chunk_size, but if the requested size is smaller samples are lost, I'm not trying to fix that here. This will at least gracefully close a wave file (update the counts) if read or write returns a size different from requested.
aplay/aplay.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
aplay/aplay.c +6 -3
@@ -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
Signature · 1 line
2.1.4
Takashi Iwai
AppliedQuoted 12 lines · David Fries
If -d was given to arecord while commit
8aa13eec80eac312e4b99423909387660fb99b8f(now reverted) was in effect, the last read would be shorter than the chunk size, butpcm_readwould read and return the chunk size, the samples were discarded, andcapture()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.
Quoted 13 lines
While the current
pcm_readcan't fail (it can exit), it is better to just fix this lurking bug in case it is "fixed" again.
---
In my case I wanted to record for 16 hours, I did get the audio, but I also found I had 3.1 million 44 byte files, which took the system 3 hours to unlink, I'm glad I at least discovered this problem the next day.. Debian has the effectively brokenpcm_read, after figuring out what was going wrong, and that the current arecord doesn't exhibit the problem I wanted to fix it anyway. There are remaining problems,pcm_readwill readchunk_size, but if the requested size is smaller samples are lost, I'm not trying to fix that here. This will at least gracefully close a wave file (update the counts) if read or write returns a size different from requested.
Applied, thanks.
Takashi
Quoted 42 lines
aplay/aplay.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)aplay/aplay.c +6
-3@@ -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 Signature · 6 lines
2.1.4 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 8 lines · David Fries
If -d was given to arecord while commit
8aa13eec80eac312e4b99423909387660fb99b8f(now reverted) was in effect, the last read would be shorter than the chunk size, butpcm_readwould read and return the chunk size, the samples were discarded, andcapture()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.
<snip>
Quoted 1 line
Debian has the effectively broken
pcm_read,
It is fortunate for me that you mentioned those details as I have just been bitten by exactly that, using arecord whilst tracking down a Portaudio issue in Debian Jessie! I was gearing up to report the bug, assuming it was in the capture system.
It seems a pity that Debian Jessie stable doesn't have a backport of the fix/revert.
Now back to tracing the original issue...
Regards
Alan
Quoted 14 lines · Alan Horstmann
Quoted 8 lines · David Fries
If -d was given to arecord while commit
8aa13eec80eac312e4b99423909387660fb99b8f(now reverted) was in effect, the last read would be shorter than the chunk size, butpcm_readwould read and return the chunk size, the samples were discarded, andcapture()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.<snip>
Quoted 1 line
Debian has the effectively broken
pcm_read,
Quoted 7 lines
It is fortunate for me that you mentioned those details as I have just been bitten by exactly that, using arecord whilst tracking down a Portaudio issue in Debian Jessie! I was gearing up to report the bug, assuming it was in the capture system.
It seems a pity that Debian Jessie stable doesn't have a backport of the fix/revert.
Glad to hear I helped.
I filed a Debian bug report with the two patches that would avoid it as Bug#821048, but it isn't going to be fixed. Denial of service is usually seen as a security issue, and this bug could run the system out of inodes, I guess it isn't seen as a high enough priority. I was able to download and compile 1.1.0-2 on Jessie which doesn't have this problem.
----------------
Please update to alsa-utils 1.1.0-2 first. In stable there will be only security patches accepted. Bug closed herewith. Backports are not maintained from us.
Elimar
----------------
Quoted 9 lines
Now back to tracing the original issue...
Regards
Alan
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Signature · 1 line
David Fries <[email protected]>