shithub: mcfs

Download patch

ref: a23fcf0c859ce06d348dc7015935b950f2d85c49
parent: 3b623f9320f90a0f5e6ea5aabf84b7eddf9fcef5
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 5 07:28:15 EST 2021

ebml: use -1 to specify unknown size; skip unknown elements properly

--- a/ebml.c
+++ b/ebml.c
@@ -343,8 +343,8 @@
 		v |= c;
 		if(v & m){
 			*out = isid ? v : (v & ~m);
-			if(!isid && *out == (1<<(7*n))-1)
-				*out = 0;
+			if(!isid && *out == (1<<(7*n))-1) /* unknown size */
+				*out = -1;
 			return n;
 		}
 		if(!isid)
@@ -429,18 +429,24 @@
 		werrstr("id: %r");
 		return -1;
 	}
-	if((s = elspec(x)) != nil)
+	if((s = elspec(x)) != nil){
 		*el = *s;
-	else
-		memset(el, 0, sizeof(*el));
-	el->id = x;
-	r = ebmluint(f, sz-n, &x);
-	n += r;
-	if(n >= sz || r < 0 || sz-n < x){
-		werrstr("sz: (sz=%lld n=%lld r=%lld x=%lld): %r", sz, n, r, x);
-		return -1;
+		el->id = x;
+		r = ebmluint(f, sz-n, &x);
+		n += r;
+		if(n >= sz || r < 0 || sz-n < x){
+			werrstr("sz: (sz=%lld n=%lld r=%lld x=%lld): %r", sz, n, r, x);
+			return -1;
+		}
+		*esz = x;
+	}else{ /* skip invalid elements */
+		while(--n > 0)
+			Bungetc(f);
+		el->id = x;
+		el->type = -1;
+		*esz = 0;
+		return 0;
 	}
-	*esz = x;
 
 	return n;
 }