git: 9front

Download patch

ref: 56c3fcc95f9607d589125781d7cb9d12bce9371c
parent: be17f0aafd9e822e2d2ed9328f0f9388bbddca22
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 30 16:55:33 EDT 2022

libtags: m4a: do not div by zero

--- a/sys/src/cmd/audio/libtags/m4a.c
+++ b/sys/src/cmd/audio/libtags/m4a.c
@@ -8,6 +8,7 @@
 tagm4a(Tagctx *ctx)
 {
 	uvlong duration;
+	uint x;
 	uchar *d;
 	int sz, type, dtype, i, skip, n;
 
@@ -101,12 +102,14 @@
 				if(ctx->read(ctx, d, 16) != 16)
 					return -1;
 				sz -= 16;
-				duration = beuint(&d[12]) / beuint(&d[8]);
+				if((x = beuint(&d[8])) > 0)
+					duration = beuint(&d[12]) / x;
 			}else if(d[1] == 1){ /* version 1 */
 				if(ctx->read(ctx, d, 28) != 28)
 					return -1;
 				sz -= 28;
-				duration = ((uvlong)beuint(&d[20])<<32 | beuint(&d[24])) / (uvlong)beuint(&d[16]);
+				if((x = beuint(&d[16])) > 0)
+					duration = ((uvlong)beuint(&d[20])<<32 | beuint(&d[24])) / (uvlong)x;
 			}
 			ctx->duration = duration * 1000;
 			continue;
--