* 'master' of https://github.com/pali/util-linux:
  tests: Add UDF hdd image with emoji label created by mkudffs 2.2
  libblkid: Fix UTF-16 support in function blkid_encode_to_utf8()
This commit is contained in:
Karel Zak 2020-02-10 13:51:23 +01:00
commit 3239663361
3 changed files with 32 additions and 2 deletions

View File

@ -237,7 +237,8 @@ size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
const unsigned char *src, size_t count)
{
size_t i, j;
uint16_t c;
uint32_t c;
uint16_t c2;
for (j = i = 0; i < count; i++) {
if (enc == BLKID_ENC_UTF16LE) {
@ -255,6 +256,17 @@ size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
} else {
return 0;
}
if ((enc == BLKID_ENC_UTF16LE || enc == BLKID_ENC_UTF16BE) &&
c >= 0xD800 && c <= 0xDBFF && i+2 < count) {
if (enc == BLKID_ENC_UTF16LE)
c2 = (src[i+2] << 8) | src[i+1];
else
c2 = (src[i+1] << 8) | src[i+2];
if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
c = 0x10000 + ((c - 0xD800) << 10) + (c2 - 0xDC00);
i += 2;
}
}
if (c == 0) {
dest[j] = '\0';
break;
@ -267,12 +279,19 @@ size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
break;
dest[j++] = (uint8_t) (0xc0 | (c >> 6));
dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
} else {
} else if (c < 0x10000) {
if (j+3 >= len)
break;
dest[j++] = (uint8_t) (0xe0 | (c >> 12));
dest[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
} else {
if (j+4 >= len)
break;
dest[j++] = (uint8_t) (0xf0 | (c >> 18));
dest[j++] = (uint8_t) (0x80 | ((c >> 12) & 0x3f));
dest[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
dest[j++] = (uint8_t) (0x80 | (c & 0x3f));
}
}
dest[j] = '\0';

View File

@ -0,0 +1,11 @@
ID_FS_BLOCK_SIZE=512
ID_FS_LABEL=😀
ID_FS_LABEL_ENC=😀
ID_FS_LOGICAL_VOLUME_ID=😀
ID_FS_TYPE=udf
ID_FS_USAGE=filesystem
ID_FS_UUID=5e3d6e3fee58c271
ID_FS_UUID_ENC=5e3d6e3fee58c271
ID_FS_VERSION=2.01
ID_FS_VOLUME_ID=😀
ID_FS_VOLUME_SET_ID=5e3d6e3fee58c271LinuxUDF

Binary file not shown.