shithub: riscv

Download patch

ref: aa14ba62fd02ffd0e7053c23b2918e7aa46bcb86
parent: 6f9838a6a5b80e0253bdc8fb194ad6f15eb655f5
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Jan 18 21:16:09 EST 2022

flacdec: do not loop forever on write/decode errors

--- a/sys/src/cmd/audio/flacdec/flacdec.c
+++ b/sys/src/cmd/audio/flacdec/flacdec.c
@@ -145,8 +145,8 @@
 		}
 	}
 	n = b * chans * len;
-	if(n > 0)
-		write(ifd, buf, n);
+	if(n > 0 && write(ifd, buf, n) != n)
+		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
 
 	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
@@ -191,7 +191,8 @@
 	if(seek > 0.0){
 		FLAC__uint64 srate;
 		do{
-			FLAC__stream_decoder_process_single(dec);
+			if(!FLAC__stream_decoder_process_single(dec))
+				break;
 			srate = FLAC__stream_decoder_get_sample_rate(dec);
 		}while(srate == 0);
 		if(!FLAC__stream_decoder_seek_absolute(dec, srate*seek)){