On Tue, 2016-12-20 at 09:07 +0000, Ahmed S. Darwish wrote: > Current pacat code reads whatever available from STDIN and writes > it directly to the playback stream. A minimal buffer is created > for each read operation; no further reads are then allowed unless > earlier read buffer has been fully consumed by a stream write. > > While quite simple, this model breaks upon the new requirements of > writing only frame-aligned data to the stream (commits #1 and #2). > The kernel read syscall can return a length much smaller than the > frame-aligned size requested, leading to invalid unaligned writes. > > This can easily be reproduced by choosing a starved STDIN backend: > > pacat /dev/random pa_stream_write() failed: EINVAL > echo 1234 | pacat pa_stream_write() failed: EINVAL > > or by playing an incomplete WAV file in raw, non-paplay, mode. > > So guard against such incomplete kernel reads by writing only in > frame-aligned sizes, while caching any trailing partial frame for > subsequent writes. > > Other operation modes are not affected. Non-raw paplay playback is > handled by libsndfile, ensuring complete reads, and recording mode > just writes to the STDOUT fd without any special needs. > > CommitReference: 22827a5e1e62 > CommitReference: 150ace90f380 > BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=98475 > BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=77595 > > Suggested-by: David Henningsson <diwic at ubuntu.com> > Signed-off-by: Ahmed S. Darwish <darwish.07 at gmail.com> > --- > src/utils/pacat.c | 98 ++++++++++++++++++++++++++++++------------------------- > 1 file changed, 53 insertions(+), 45 deletions(-) Thanks! Applied. -- Tanu https://www.patreon.com/tanuk