shithub: cuefs

Download patch

ref: 6c63f62f39fb93e91d0ac163bd8a3f79872d0ef0
parent: 788bc6b0f013195bdfd502955b0b8accb965d949
author: Tevo <[email protected]>
date: Sat Jan 16 22:07:59 EST 2021

Fix crash when reading small portions of wave headers

--- a/BUGS
+++ b/BUGS
@@ -3,7 +3,12 @@
 • everything will get resampled to 44100Hz/16bit/2channel
 • the codebase is a mess
 • reading concurrently from the same fid might break decoding logic, or be unecessarily slow (does that ever happen?)
-• zuke causes wavserve to do a negative readdec() somehow
+• zuke with wav keeps requesting the file header at offsets 0, 4 and 8; never starts playing
 • some parser/cuefs behavior might be non-standard or undesirable
 	- for example, there's currently no way to split tracks without including the pregap either at the end of the last track or beggining of current one
 • parser is incomplete
+• splitting tracks from → to the same format could some times be done more efficiently, skipping the decode (and resample) → encode process; this could be especially beneficial to lossy formats since there would be no reencoding.
+• some cuesheets have metadata (that would otherwise have nowhere to be in the sheet) stored in comments, in a somewhat semistandard manner, i.e.
+		REM GENRE "Progressive Rock"
+		REM DATE 2002
+	it probably wouldn't hurt to try parsing some of those; not a high priority at the moment
--- a/fs.c
+++ b/fs.c
@@ -284,7 +284,7 @@
 {
 	Wavehdr hdr;
 	Decoder *dec;
-	ulong offset, count, hcount;
+	long offset, count, hcount;
 
 	offset = r->ifcall.offset;
 	count = r->ifcall.count;
@@ -291,16 +291,25 @@
 
 	hcount = 0;
 
+	debug("wavserve: count = %ld, offset = %ld, r->ofcall.count = %ld", 
+		count, offset, r->ofcall.count);
+
 	/* 44 == start of pcm data */
 	if(offset < 44)
 	{
 		hcount = 44 - offset;
+		if(count < hcount)
+			hcount = count;
 		count -= hcount;
-		offset = 0;
-		fillwavehdr(&hdr, 2, 44100, 16, count);
-		memcpy(r->ofcall.data, &hdr, hcount);
+		fillwavehdr(&hdr, 2, 44100, 16, entrylen(e));
+		memcpy(r->ofcall.data, &hdr+offset, hcount);
+		r->ofcall.count += hcount;
+		offset = 44;
 	}
 
+	debug("; after header: count = %ld, hcount = %ld, offset = %ld, r->ofcall.count = %ld\n",
+		count, hcount, offset, r->ofcall.count);
+
 	if(count == 0)
 	{
 		respond(r, nil);
@@ -308,7 +317,7 @@
 	}
 
 	dec = reqdec(e, r, offset);
-	r->ofcall.count = readdec(dec, r->ofcall.data+hcount, count);
+	r->ofcall.count += readdec(dec, r->ofcall.data+hcount, count);
 	respond(r, nil);
 }