diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2006-07-25 18:12:57 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-07-25 18:12:57 +0000 |
commit | b40eb3d6627214a7e5a886f972022576799568ec (patch) | |
tree | 9158eadb70ce070919a1dac0fe8ba8521002f7f8 | |
parent | e0d64b95db0664bcf374dc6c52707adfac910759 (diff) | |
download | rockbox-b40eb3d6627214a7e5a886f972022576799568ec.tar.gz rockbox-b40eb3d6627214a7e5a886f972022576799568ec.zip |
Fixed unicode buffer overflow issue (metadata parser crashed with some
mp3 files).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10324 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugin.h | 4 | ||||
-rw-r--r-- | firmware/common/unicode.c | 8 | ||||
-rw-r--r-- | firmware/include/rbunicode.h | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/apps/plugin.h b/apps/plugin.h index a663ce5f7d..3cd3fa6b63 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -327,8 +327,8 @@ struct plugin_api { | |||
327 | /* unicode stuff */ | 327 | /* unicode stuff */ |
328 | const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs); | 328 | const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs); |
329 | unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count); | 329 | unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count); |
330 | unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, unsigned int count); | 330 | unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count); |
331 | unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, unsigned int count); | 331 | unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count); |
332 | unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8); | 332 | unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8); |
333 | unsigned long (*utf8length)(const unsigned char *utf8); | 333 | unsigned long (*utf8length)(const unsigned char *utf8); |
334 | 334 | ||
diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c index 83780393d5..1dc7eedc3e 100644 --- a/firmware/common/unicode.c +++ b/firmware/common/unicode.c | |||
@@ -170,11 +170,11 @@ unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8, | |||
170 | 170 | ||
171 | /* Recode a UTF-16 string with little-endian byte ordering to UTF-8 */ | 171 | /* Recode a UTF-16 string with little-endian byte ordering to UTF-8 */ |
172 | unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, | 172 | unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, |
173 | unsigned int count) | 173 | int count) |
174 | { | 174 | { |
175 | unsigned long ucs; | 175 | unsigned long ucs; |
176 | 176 | ||
177 | while (count != 0) { | 177 | while (count > 0) { |
178 | /* Check for a surrogate pair */ | 178 | /* Check for a surrogate pair */ |
179 | if (utf16[1] >= 0xD8 && utf16[1] < 0xE0) { | 179 | if (utf16[1] >= 0xD8 && utf16[1] < 0xE0) { |
180 | ucs = 0x10000 + ((utf16[0] << 10) | ((utf16[1] - 0xD8) << 18) | 180 | ucs = 0x10000 + ((utf16[0] << 10) | ((utf16[1] - 0xD8) << 18) |
@@ -193,11 +193,11 @@ unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, | |||
193 | 193 | ||
194 | /* Recode a UTF-16 string with big-endian byte ordering to UTF-8 */ | 194 | /* Recode a UTF-16 string with big-endian byte ordering to UTF-8 */ |
195 | unsigned char* utf16BEdecode(const unsigned char *utf16, unsigned char *utf8, | 195 | unsigned char* utf16BEdecode(const unsigned char *utf16, unsigned char *utf8, |
196 | unsigned int count) | 196 | int count) |
197 | { | 197 | { |
198 | unsigned long ucs; | 198 | unsigned long ucs; |
199 | 199 | ||
200 | while (count != 0) { | 200 | while (count > 0) { |
201 | if (*utf16 >= 0xD8 && *utf16 < 0xE0) { /* Check for a surrogate pair */ | 201 | if (*utf16 >= 0xD8 && *utf16 < 0xE0) { /* Check for a surrogate pair */ |
202 | ucs = 0x10000 + (((utf16[0] - 0xD8) << 18) | (utf16[1] << 10) | 202 | ucs = 0x10000 + (((utf16[0] - 0xD8) << 18) | (utf16[1] << 10) |
203 | | ((utf16[2] - 0xDC) << 8) | utf16[3]); | 203 | | ((utf16[2] - 0xDC) << 8) | utf16[3]); |
diff --git a/firmware/include/rbunicode.h b/firmware/include/rbunicode.h index 0e12890736..66726d10b5 100644 --- a/firmware/include/rbunicode.h +++ b/firmware/include/rbunicode.h | |||
@@ -19,8 +19,8 @@ | |||
19 | /* Encode a UCS value as UTF-8 and return a pointer after this UTF-8 char. */ | 19 | /* Encode a UCS value as UTF-8 and return a pointer after this UTF-8 char. */ |
20 | unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); | 20 | unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); |
21 | unsigned char* iso_decode(const unsigned char *latin1, unsigned char *utf8, int cp, int count); | 21 | unsigned char* iso_decode(const unsigned char *latin1, unsigned char *utf8, int cp, int count); |
22 | unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, unsigned int count); | 22 | unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, int count); |
23 | unsigned char* utf16BEdecode(const unsigned char *utf16, unsigned char *utf8, unsigned int count); | 23 | unsigned char* utf16BEdecode(const unsigned char *utf16, unsigned char *utf8, int count); |
24 | unsigned char* utf16decode(const unsigned char *utf16, unsigned char *utf8, unsigned int count); | 24 | unsigned char* utf16decode(const unsigned char *utf16, unsigned char *utf8, unsigned int count); |
25 | unsigned long utf8length(const unsigned char *utf8); | 25 | unsigned long utf8length(const unsigned char *utf8); |
26 | const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); | 26 | const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); |