Skip to contentSkip to conversation

Bug in NLS UTF-8 code

PATCH New Liyang Hu 1 participant 1 message Apr 1, 2002

lore
Share & tools
lore

Liyang Hu

author
#0 lore raw

PATCH 1/1 Bug in NLS UTF-8 code

Hi,

I've recently (actually, last month, but I had been a bit too busy since then) come across a wee problem, in what I originally thought was the VFAT code -- having `utf8' as one of the options, creating UTF-8 file names on a VFAT partition mysteriously gains a couple of (random) characters just after the UTF-8 escaped character: eg. touch "fooCbar" where C is an UTF-8 escape sequence ends up creating a file named "fooCRbar". (R being some random character.)

I eventually tracked it down to one line in fs/nls/nls_base.c -- the UCS-2 (wchar_t) string pointer was being incremented too fast. After consulting Ogawa Hirofumi-san on the subject, he mentioned that include/linux/nls.h also needs to be changed for proper UTF-8 support in the NLS code.

Patch enclosed below.

/Liyang

----8<----snip----8<----

fs/nls/nls_base.c renamed from fs/nls/nls_base.c.orig +2 -2
@@ -1,5 +1,5 @@
 /*
- * linux/fs/nls.c
+ * linux/fs/nls_base.c
  *
  * Native language support--charsets and unicode translations.
  * By Gordon Chaffee 1996, 1997
@@ -93,7 +93,7 @@
 				ip++;
 				n--;
 			} else {
-				op += size;
+				op++;
 				ip += size;
 				n -= size;
 			}
include/linux/nls.h renamed from include/linux/nls.h.orig +1 -1
@@ -18,7 +18,7 @@
 };
 
 /* this value hold the maximum octet of charset */
-#define NLS_MAX_CHARSET_SIZE 3
+#define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
 
 /* nls.c */
 extern int register_nls(struct nls_table *);

----8<----snip----8<----

Signature · 3 lines
.--{ Liyang HU }--{ http://nerv.cx/ }--{ Caius@Cam }--{ ICQ: 39391385 }--.
| :: Well, we just happen to *have* an infinite number of monkeys! ::::: |
| ::::::: http://stats.distributed.net/rc5-64/psummary.php3?id=284324 :: |