Skip to content

Commit 5a1bd13

Browse files
committed
Wrong ID3 data if data not UTF-8 #606
1 parent 2ef8cf7 commit 5a1bd13

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/Audio.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Created on: Oct 26.2018
55
*
6-
* Version 3.0.7
7-
* Updated on: Oct 08.2023
6+
* Version 3.0.7a
7+
* Updated on: Nov 11.2023
88
* Author: Wolle (schreibfaul1)
99
*
1010
*/
@@ -1042,14 +1042,16 @@ bool Audio::latinToUTF8(char* buff, size_t bufflen){
10421042
pos = 0;
10431043

10441044
while(buff[pos] != 0){
1045-
len = strlen(buff);
1046-
if(buff[pos] >= 0x80 && buff[pos+1] < 0x80){ // is not UTF8, is latin?
1047-
for(int i = len+1; i > pos; i--){
1045+
if ((buff[pos] & 0x80) == 0) {pos++; continue;}
1046+
else{
1047+
len = strlen(buff);
1048+
for(int i = len + 1; i > pos; i--){
10481049
buff[i+1] = buff[i];
10491050
}
10501051
uint8_t c = buff[pos];
1051-
buff[pos++] = 0xc0 | ((c >> 6) & 0x1f); // 2+1+5 bits
1052-
buff[pos++] = 0x80 | ((char)c & 0x3f); // 1+1+6 bits
1052+
buff[pos] = 0xc0 | ((c >> 6)& 0x1f); // 2+1+5 bits
1053+
pos++;
1054+
buff[pos] = 0x80 | ((char)c & 0x3f); // 1+1+6 bits
10531055
}
10541056
pos++;
10551057
if(pos > bufflen -3){
@@ -1640,17 +1642,15 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
16401642

16411643
if(!isUnicode){
16421644
uint16_t j = 0, k = 0;
1643-
j = 0;
1644-
k = 0;
16451645
while(j < fs) {
1646-
if(m_ibuff[j] == 0x0A) m_ibuff[j] = 0x20; // replace LF by space
16471646
if(m_ibuff[j] > 0x1F) {
1648-
m_ibuff[k] = m_ibuff[j];
1647+
m_ibuff[k] = m_ibuff[j]; //remove non printables
16491648
k++;
16501649
}
16511650
j++;
1652-
} //remove non printables
1653-
if(k>0) m_ibuff[k] = 0; else m_ibuff[0] = 0; // new termination
1651+
}
1652+
m_ibuff[k] = '\0'; // new termination
1653+
latinToUTF8(m_ibuff, k - 1);
16541654
}
16551655
showID3Tag(tag, m_ibuff);
16561656
return fs;

src/Audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Created on: Oct 28,2018
55
*
6-
* Version 3.0.7
7-
* Updated on: Oct 08.2023
6+
* Version 3.0.7a
7+
* Updated on: Nov 11.2023
88
* Author: Wolle (schreibfaul1)
99
*/
1010

0 commit comments

Comments
 (0)