WSL2-Linux-Kernel/fs/hfsplus
Hin-Tak Leung 017f8da43e hfsplus: fix worst-case unicode to char conversion of file names and attributes
This is a series of 3 patches which corrects issues in HFS+ concerning
the use of non-english file names and attributes.  Names and attributes
are stored internally as UTF-16 units up to a fixed maximum size, and
convert to and from user-representation by NLS.  The code incorrectly
assume that NLS string lengths are equal to unicode lengths, which is
only true for English ascii usage.

This patch (of 3):

The HFS Plus Volume Format specification (TN1150) states that file names
are stored internally as a maximum of 255 unicode characters, as defined
by The Unicode Standard, Version 2.0 [Unicode, Inc.  ISBN
0-201-48345-9].  File names are converted by the NLS system on Linux
before presented to the user.

255 CJK characters converts to UTF-8 with 1 unicode character to up to 3
bytes, and to GB18030 with 1 unicode character to up to 4 bytes.  Thus,
trying in a UTF-8 locale to list files with names of more than 85 CJK
characters results in:

    $ ls /mnt
    ls: reading directory /mnt: File name too long

The receiving buffer to hfsplus_uni2asc() needs to be 255 x
NLS_MAX_CHARSET_SIZE bytes, not 255 bytes as the code has always been.

Similar consideration applies to attributes, which are stored internally
as a maximum of 127 UTF-16BE units.  See XNU source for an up-to-date
reference on attributes.

Strictly speaking, the maximum value of NLS_MAX_CHARSET_SIZE = 6 is not
attainable in the case of conversion to UTF-8, as going beyond 3 bytes
requires the use of surrogate pairs, i.e.  consuming two input units.

Thanks Anton Altaparmakov for reviewing an earlier version of this
change.

This patch fixes all callers of hfsplus_uni2asc(), and also enables the
use of long non-English file names in HFS+.  The getting and setting,
and general usage of long non-English attributes requires further
forthcoming work, in the following patches of this series.

[akpm@linux-foundation.org: fix build]
Signed-off-by: Hin-Tak Leung <htl10@users.sourceforge.net>
Reviewed-by: Anton Altaparmakov <anton@tuxera.com>
Cc: Vyacheslav Dubeyko <slava@dubeyko.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Sougata Santra <sougata@tuxera.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-06-06 16:08:09 -07:00
..
Kconfig hfsplus: add necessary declarations for POSIX ACLs support 2013-09-11 15:59:00 -07:00
Makefile hfsplus: integrate POSIX ACLs support into driver 2013-09-11 15:59:01 -07:00
acl.h hfsplus: use generic posix ACL infrastructure 2014-01-25 23:58:20 -05:00
attributes.c fs/hfsplus/attributes.c: add __init to hfsplus_create_attr_tree_cache() 2014-04-03 16:21:26 -07:00
bfind.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
bitmap.c hfsplus: remove duplicated message prefix in hfsplus_block_free() 2013-04-30 17:04:05 -07:00
bnode.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
brec.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
btree.c hfsplus: add metadata file's clump size calculation functionality 2013-11-13 12:09:32 +09:00
catalog.c hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
dir.c hfsplus: fix worst-case unicode to char conversion of file names and attributes 2014-06-06 16:08:09 -07:00
extents.c fs/hfsplus/extents.c: fix concurrent acess of alloc_blocks 2014-04-03 16:21:26 -07:00
hfsplus_fs.h fs/hfsplus/attributes.c: add __init to hfsplus_create_attr_tree_cache() 2014-04-03 16:21:26 -07:00
hfsplus_raw.h hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
inode.c hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
ioctl.c hfsplus: add support of manipulation by attributes file 2013-02-27 19:10:10 -08:00
options.c hfsplus: fix remount issue 2014-03-04 07:55:49 -08:00
part_tbl.c hfsplus: ensure bio requests are not smaller than the hardware sectors 2011-07-22 16:37:44 +02:00
posix_acl.c hfsplus: use generic posix ACL infrastructure 2014-01-25 23:58:20 -05:00
super.c Major changes for 3.14 include support for the newly added ZERO_RANGE 2014-04-04 15:39:39 -07:00
tables.c
unicode.c Don't pass inode to ->d_hash() and ->d_compare() 2013-06-29 12:57:36 +04:00
wrapper.c block: submit_bio_wait() conversions 2013-11-24 16:33:41 -07:00
xattr.c hfsplus: fix worst-case unicode to char conversion of file names and attributes 2014-06-06 16:08:09 -07:00
xattr.h hfsplus: use xattr handlers for removexattr 2014-01-31 14:44:39 -05:00
xattr_security.c hfsplus: integrate POSIX ACLs support into driver 2013-09-11 15:59:01 -07:00
xattr_trusted.c hfsplus: rework functionality of getting, setting and deleting of extended attributes 2013-02-27 19:10:10 -08:00
xattr_user.c hfsplus: rework functionality of getting, setting and deleting of extended attributes 2013-02-27 19:10:10 -08:00