shithub: riscv

Download patch

ref: 916022699ac940621052521a69d3e7b530f537f4
parent: b4e31923d4c4d447eb5c5a9153f26f05a56c9d08
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Oct 12 21:18:53 EDT 2022

libtags: vorbis, opus: ignore tags past the ogg page

As it is implemented right now, OGG pages are not treated properly,
so in case of huge embedded pictures inside metadata the file could
end up ignore by audio/readtags and audio/mkplist. Workaround by
ignoring tags that span across pages for now.

--- a/sys/src/cmd/audio/libtags/opus.c
+++ b/sys/src/cmd/audio/libtags/opus.c
@@ -5,10 +5,10 @@
 {
 	char *v;
 	uchar *d, h[4];
-	int sz, numtags, i, npages;
+	int sz, numtags, i, npages, pgend;
 
 	d = (uchar*)ctx->buf;
-	for(npages = 0; npages < 2; npages++){
+	for(npages = pgend = 0; npages < 2; npages++){
 		int nsegs;
 		if(ctx->read(ctx, d, 27) != 27)
 			return -1;
@@ -28,6 +28,8 @@
 			ctx->channels = d[1];
 			ctx->samplerate = leuint(&d[4]);
 		}else if(memcmp(&d[nsegs], "OpusTags", 8) == 0){
+			/* FIXME - embedded pics make tags span multiple packets */
+			pgend = ctx->seek(ctx, 0, 1) + sz;
 			break;
 		}
 
@@ -47,6 +49,9 @@
 				return -1;
 			if((sz = leuint(h)) < 0)
 				return -1;
+			/* FIXME - embedded pics make tags span multiple packets */
+			if(pgend < ctx->seek(ctx, 0, 1)+sz)
+				break;
 
 			if(ctx->bufsz < sz+1){
 				if(ctx->seek(ctx, sz, 1) < 0)
--- a/sys/src/cmd/audio/libtags/vorbis.c
+++ b/sys/src/cmd/audio/libtags/vorbis.c
@@ -37,11 +37,11 @@
 {
 	char *v;
 	uchar *d, h[4];
-	int sz, numtags, i, npages;
+	int sz, numtags, i, npages, pgend;
 
 	d = (uchar*)ctx->buf;
 	/* need to find vorbis frame with type=3 */
-	for(npages = 0; npages < 2; npages++){ /* vorbis comment is the second header */
+	for(npages = pgend = 0; npages < 2; npages++){ /* vorbis comment is the second header */
 		int nsegs;
 		if(ctx->read(ctx, d, 27) != 27)
 			return -1;
@@ -54,8 +54,11 @@
 			return -1;
 		for(sz = i = 0; i < nsegs; sz += d[i++]);
 
-		if(d[nsegs] == 3) /* comment */
+		if(d[nsegs] == 3){ /* comment */
+			/* FIXME - embedded pics make tags span multiple packets */
+			pgend = ctx->seek(ctx, 0, 1) + sz;
 			break;
+		}
 		if(d[nsegs] == 1 && sz >= 28){ /* identification */
 			if(ctx->read(ctx, d, 28) != 28)
 				return -1;
@@ -82,6 +85,9 @@
 				return -1;
 			if((sz = leuint(h)) < 0)
 				return -1;
+			/* FIXME - embedded pics make tags span multiple packets */
+			if(pgend < ctx->seek(ctx, 0, 1)+sz)
+				break;
 
 			if(ctx->bufsz < sz+1){
 				if(ctx->seek(ctx, sz, 1) < 0)