Re: [PATCH] nls: add surrogate pair support in nls utf8.

From: Namjae Jeon
Date: Mon Dec 05 2011 - 18:41:09 EST


2011/12/5 Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>:
> On Sun, 4 Dec 2011, Namjae Jeon wrote:
>
>> It allows surrogate pair in nls utf8.
>
> That's a pretty brief description.
okay~ I will rewrite more.
>
>> --- a/fs/nls/nls_utf8.c
>> +++ b/fs/nls/nls_utf8.c
>> @@ -30,13 +30,24 @@ static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
>> Â{
>> Â Â Â int n;
>> Â Â Â unicode_t u;
>> + Â Â u16 *op;
>>
>> + Â Â op = uni;
>> Â Â Â n = utf8_to_utf32(rawstring, boundlen, &u);
>> - Â Â if (n < 0 || u > MAX_WCHAR_T) {
>> + Â Â if (n < 0 || u > UNICODE_MAX) {
>> Â Â Â Â Â Â Â *uni = 0x003f; Â/* ? */
>> Â Â Â Â Â Â Â return -EINVAL;
>> Â Â Â }
>> - Â Â *uni = (wchar_t) u;
>> +
>> + Â Â if (u >= PLANE_SIZE) {
>> + Â Â Â Â Â Â u -= PLANE_SIZE;
>> + Â Â Â Â Â Â *op++ = (wchar_t) (SURROGATE_PAIR |
>> + Â Â Â Â Â Â ((u >> 10) & SURROGATE_BITS));
>> + Â Â Â Â Â Â *op++ = (wchar_t) (SURROGATE_PAIR |
>> + Â Â Â Â Â Â SURROGATE_LOW | (u & SURROGATE_BITS));
>> + Â Â Â Â Â Â } else
>> + Â Â Â Â Â Â Â Â Â Â *op++ = (wchar_t) u;
>> +
>> Â Â Â return n;
>> Â}
>
> Firstly, have you checked whether the callers of this function expect
> to receive back more than one 16-bit value? ÂMaybe you will overrun
> their buffers by doing this.
Hi Alan.
first Thanks for your review.
yes, you're right. and yes I have checked it on FAT fs, I will try to
post the below FAT patch after this patch is applied.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -555,7 +555,10 @@ xlate_to_uni(const unsigned char *name, int len,
unsigned char *outname,
return -EINVAL;
ip += charlen;
i += charlen;
- op += 2;
+ if (charlen == sizeof(unicode_t))
+ op += 4;
+ else
+ op += 2;
}
}
-----------------------------------------------------------------------------------------------------------------------------------

>
> Secondly, you shouldn't have to make all these changes. ÂJust call
> utf8s_to_utf16s(); then all you have to worry about is changing an
> invalid character to a '?'.
Currently there are two paths along mount option. if using -o utf8
mount option, utf8s_to_utf16s have been used in xlate_to_uni of FAT.
and if using iocharset=utf8, char2uni have been used..
nls->char2uni works on a single charachter while utf8s_to_utf16s works
on whole string.
when the mount option(uni_xlate) that require scanning character by
character is used it is needed.
>
> Alan Stern
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/