From 3673aa721509eaa8a7c63ee1045db81daba82803 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Wed, 31 Mar 2021 22:20:56 +0200 Subject: [PATCH] [player] Protect against crash if very first input_write() is FLAG_ERROR --- src/player.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/player.c b/src/player.c index 2e3e0643..d4f9c0b2 100644 --- a/src/player.c +++ b/src/player.c @@ -1179,13 +1179,15 @@ source_read(int *nbytes, int *nsamples, uint8_t *buf, int len) // We can get into this condition if a) we finished reading, but are still // playing (playing_now is non-null), or b) the calling loop tries to catch up // with an overrun or a deficit, but playback ended in the first iteration (in - // which case playing_now is null) + // which case playing_now is null). Note that a) also can occur if the input + // starts with input_write(NULL, NULL, INPUT_FLAG_ERROR). if (!pb_session.reading_now) { // This is only for case a). If we are in case b) the session was zeroed, - // which means nsamples will become zero. + // which means nsamples will become zero. Quality can be zero if the input + // failed immediately, i.e. never passed INPUT_FLAG_QUALITY. *nbytes = len; - *nsamples = BTOS(*nbytes, pb_session.quality.bits_per_sample, pb_session.quality.channels); + *nsamples = (len != 0) ? BTOS(*nbytes, pb_session.quality.bits_per_sample, pb_session.quality.channels) : 0; // In case a) this advances playback position and possibly ends playback, // i.e. sets playing_now to null