git: 9front

Download patch

ref: c51f35a4e8493b5193167885681e0803dad06eb1
parent: e35f62c0d85e159724d30189d0d266ffeb94b9a8
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Sep 27 21:17:10 EDT 2021

libtags: opus: fix duration on truncated files

--- a/sys/src/cmd/audio/libtags/opus.c
+++ b/sys/src/cmd/audio/libtags/opus.c
@@ -8,8 +8,7 @@
 	int sz, numtags, i, npages;
 
 	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 = 0; npages < 2; npages++){
 		int nsegs;
 		if(ctx->read(ctx, d, 27) != 27)
 			return -1;
@@ -76,7 +75,7 @@
 				break;
 			for(; v != nil && v < ctx->buf+sz;){
 				v = memchr(v, 'O', ctx->buf+sz - v - 14);
-				if(v != nil && v[1] == 'g' && v[2] == 'g' && v[3] == 'S' && (v[5] & 4) == 4){ /* last page */
+				if(v != nil && v[1] == 'g' && v[2] == 'g' && v[3] == 'S'){
 					uvlong g = leuint(v+6) | (uvlong)leuint(v+10)<<32;
 					ctx->duration = g * 1000 / 48000; /* granule positions are always 48KHz */
 					return 0;
--