From f0fcfdc30f529d670b966e40c026a07bb0c2a65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 22 Jun 2017 10:38:08 +0200 Subject: [PATCH 1/2] libblkid: udf: Fix parsing of UDF dstring structures First byte of dstring is OSTA Compression ID and the last byte is length of recorded bytes (including first byte). Last byte is not a part of recorded characters, therefore it should not be treated as data to decode. --- libblkid/src/superblocks/udf.c | 66 +++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/libblkid/src/superblocks/udf.c b/libblkid/src/superblocks/udf.c index 602cf408e..832acb1b4 100644 --- a/libblkid/src/superblocks/udf.c +++ b/libblkid/src/superblocks/udf.c @@ -19,13 +19,15 @@ #include "superblocks.h" struct dstring128 { + uint8_t cid; + uint8_t c[126]; uint8_t clen; - uint8_t c[127]; } __attribute__((packed)); struct dstring32 { + uint8_t cid; + uint8_t c[30]; uint8_t clen; - uint8_t c[31]; } __attribute__((packed)); struct volume_descriptor { @@ -80,15 +82,22 @@ static inline int gen_uuid_from_volset_id(unsigned char uuid[17], struct dstring { size_t i; size_t len; + size_t clen; size_t nonhexpos; unsigned char buf[17]; memset(buf, 0, sizeof(buf)); - if (volset_id->clen == 8) - len = blkid_encode_to_utf8(BLKID_ENC_LATIN1, buf, sizeof(buf), volset_id->c, 127); - else if (volset_id->clen == 16) - len = blkid_encode_to_utf8(BLKID_ENC_UTF16BE, buf, sizeof(buf), volset_id->c, 127); + clen = volset_id->clen; + if (clen > 0) + --clen; + if (clen > sizeof(volset_id->c)) + clen = sizeof(volset_id->c); + + if (volset_id->cid == 8) + len = blkid_encode_to_utf8(BLKID_ENC_LATIN1, buf, sizeof(buf), volset_id->c, clen); + else if (volset_id->cid == 16) + len = blkid_encode_to_utf8(BLKID_ENC_UTF16BE, buf, sizeof(buf), volset_id->c, clen); else return -1; @@ -215,14 +224,19 @@ real_blksz: break; if (type == 1) { /* TAG_ID_PVD */ if (!have_volid) { + uint8_t cid = vd->type.primary.ident.cid; uint8_t clen = vd->type.primary.ident.clen; - if (clen == 8) + if (clen > 0) + --clen; + if (clen > sizeof(vd->type.primary.ident.c)) + clen = sizeof(vd->type.primary.ident.c); + if (cid == 8) have_volid = !blkid_probe_set_utf8_id_label(pr, "VOLUME_ID", - vd->type.primary.ident.c, 31, + vd->type.primary.ident.c, clen, BLKID_ENC_LATIN1); - else if (clen == 16) + else if (cid == 16) have_volid = !blkid_probe_set_utf8_id_label(pr, "VOLUME_ID", - vd->type.primary.ident.c, 31, + vd->type.primary.ident.c, clen, BLKID_ENC_UTF16BE); } if (!have_uuid) { @@ -260,14 +274,19 @@ real_blksz: have_uuid = !blkid_probe_strncpy_uuid(pr, uuid, sizeof(uuid)); } if (!have_volsetid) { + uint8_t cid = vd->type.primary.volset_id.cid; uint8_t clen = vd->type.primary.volset_id.clen; - if (clen == 8) + if (clen > 0) + --clen; + if (clen > sizeof(vd->type.primary.volset_id.c)) + clen = sizeof(vd->type.primary.volset_id.c); + if (cid == 8) have_volsetid = !blkid_probe_set_utf8_id_label(pr, "VOLUME_SET_ID", - vd->type.primary.volset_id.c, 127, + vd->type.primary.volset_id.c, clen, BLKID_ENC_LATIN1); - else if (clen == 16) + else if (cid == 16) have_volsetid = !blkid_probe_set_utf8_id_label(pr, "VOLUME_SET_ID", - vd->type.primary.volset_id.c, 127, + vd->type.primary.volset_id.c, clen, BLKID_ENC_UTF16BE); } } else if (type == 6) { /* TAG_ID_LVD */ @@ -298,24 +317,29 @@ real_blksz: * LABEL also from this field. Program newfs_udf (from UDFclient) * when formatting disk set this field from user option Disc Name. */ + uint8_t cid = vd->type.logical.logvol_id.cid; uint8_t clen = vd->type.logical.logvol_id.clen; - if (clen == 8) { + if (clen > 0) + --clen; + if (clen > sizeof(vd->type.logical.logvol_id.c)) + clen = sizeof(vd->type.logical.logvol_id.c); + if (cid == 8) { if (!have_label) have_label = !blkid_probe_set_utf8label(pr, - vd->type.logical.logvol_id.c, 127, + vd->type.logical.logvol_id.c, clen, BLKID_ENC_LATIN1); if (!have_logvolid) have_logvolid = !blkid_probe_set_utf8_id_label(pr, "LOGICAL_VOLUME_ID", - vd->type.logical.logvol_id.c, 127, + vd->type.logical.logvol_id.c, clen, BLKID_ENC_LATIN1); - } else if (clen == 16) { + } else if (cid == 16) { if (!have_label) have_label = !blkid_probe_set_utf8label(pr, - vd->type.logical.logvol_id.c, - 127, BLKID_ENC_UTF16BE); + vd->type.logical.logvol_id.c, clen, + BLKID_ENC_UTF16BE); if (!have_logvolid) have_logvolid = !blkid_probe_set_utf8_id_label(pr, "LOGICAL_VOLUME_ID", - vd->type.logical.logvol_id.c, 127, + vd->type.logical.logvol_id.c, clen, BLKID_ENC_UTF16BE); } } From 56dce6b7fc60e837e4a64fd9091cc28f22c089c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 22 Jun 2017 10:38:24 +0200 Subject: [PATCH 2/2] tests: Add UDF hdd image which label has length 30 characters Structure dstring for label has 32 bytes, first byte is 8 (Compression ID), last byte is 30 (count of 8bit characters in label). Therefore label is not nul terminated and dstring parser needs to handle it (fixed in previous commit). $ dd if=/dev/zero of=udf-hdd-mkudffs-1.3-6.img bs=1M count=10 $ mkudffs -l AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -b 512 udf-hdd-mkudffs-1.3-6.img --- .../blkid/low-probe-udf-hdd-mkudffs-1.3-6 | 9 +++++++++ .../blkid/images-fs/udf-hdd-mkudffs-1.3-6.img.xz | Bin 0 -> 2360 bytes 2 files changed, 9 insertions(+) create mode 100644 tests/expected/blkid/low-probe-udf-hdd-mkudffs-1.3-6 create mode 100644 tests/ts/blkid/images-fs/udf-hdd-mkudffs-1.3-6.img.xz diff --git a/tests/expected/blkid/low-probe-udf-hdd-mkudffs-1.3-6 b/tests/expected/blkid/low-probe-udf-hdd-mkudffs-1.3-6 new file mode 100644 index 000000000..4add7a3ad --- /dev/null +++ b/tests/expected/blkid/low-probe-udf-hdd-mkudffs-1.3-6 @@ -0,0 +1,9 @@ +ID_FS_LABEL=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +ID_FS_LABEL_ENC=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +ID_FS_LOGICAL_VOLUME_ID=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +ID_FS_TYPE=udf +ID_FS_USAGE=filesystem +ID_FS_UUID=59419a34ca436d67 +ID_FS_UUID_ENC=59419a34ca436d67 +ID_FS_VOLUME_ID=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +ID_FS_VOLUME_SET_ID=59419a34ca436d67LinuxUDF diff --git a/tests/ts/blkid/images-fs/udf-hdd-mkudffs-1.3-6.img.xz b/tests/ts/blkid/images-fs/udf-hdd-mkudffs-1.3-6.img.xz new file mode 100644 index 0000000000000000000000000000000000000000..393ab9e697e5ea8a74d51d5df1cc2e59d0b224c9 GIT binary patch literal 2360 zcmexsUKJ6=z`*kC+7>q^21Q001_lO!^ATtM|G&+AKbCD7m#_X}-kbHy9``5<20w_DI9l5EsQkO@eXeHD zyQ*ge0xq9pb=`Jyi955)TsIS^9n#$nb&93^jF%G)l_#F) zT}5%Fj_m4@@VYr!zx5zPi}a1xT>sDYTzdAeaK@C2#)>-qLT`-yT|J!_ zxyLjLvN5eRk2$pY!ph}2YjlM68vZ_Fc1`QRg+)ms3$|5PNj>znE@wWb1-eYv)$U7f)T}HNWqiU}T`$=dyIm;J^(xY$J;-ayoD3$((QA zWWVGX?59O5sn``@2#nCvK7xviLnm%4MOC zPgM4bVn608_ap5hJ(usYuF|r5wX@~N$~{c2mvepxZcTl-c>A7NbL~#-$^Y2j~#b6KTKqvcdUfFa?jEShfO+@YjnMTFROgl*|{p{ zkLDWtU6t+M-tRbMT({IkXKhO~r-!SC+^&*+x?0X}Kb+`)^-ZOv{dcN?|3=UL8dtXc zjMsKJmfcGJbnL+93qMxxT@|qToyI!8LmSOilbEl*S?a&vB3k>?$@N^nJJict-d?E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