shithub: libtags

Download patch

ref: 2c7c27be5decdf67bd0770b2ddce538e5d584739
parent: 1848c04ac0e8c83bf21bc448e01caf0530f1bc19
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Mar 5 18:27:15 EST 2024

iso88591toutf8: detect undefined chars and copy as is (fixes utf8 id3v1)

--- a/8859.c
+++ b/8859.c
@@ -2,11 +2,15 @@
 #include "tagspriv.h"
 
 int
-iso88591toutf8(uint8_t *o, int osz, const uint8_t *s, int sz)
+iso88591toutf8(uint8_t *o0, int osz, const uint8_t *s, int sz)
 {
+	uint8_t *o;
 	int i;
 
+	o = o0;
 	for(i = 0; i < sz && osz > 1 && s[i] != 0; i++){
+		if(s[i] >= 0x7f && s[i] <= 0x9f) /* not expecting control chars */
+			goto asis;
 		if(s[i] >= 0xa0 && osz < 3)
 			break;
 
@@ -26,4 +30,12 @@
 
 	*o = 0;
 	return i;
+
+asis:
+	/* FIXME - copy within UTF-8 chars boundaries */
+	if(sz >= osz)
+		sz = osz-1;
+	memmove(o0, s, sz);
+	o0[sz] = 0;
+	return sz;
 }
binary files a/input/noise.id3v1.mp3 b/input/noise.id3v1.mp3 differ