]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_scrub: reduce size of struct name_entry
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:10 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jul 2024 22:36:58 +0000 (15:36 -0700)
libicu doesn't support processing strings longer than 2GB in length, and
we never feed the unicrash code a name longer than about 300 bytes.
Rearrange the structure to reduce the head structure size from 56 bytes
to 44 bytes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/unicrash.c

index 63694c39a886153fbef26ee0d40bd747f4d8d91b..74c0fe1f9f84bd1d014110614083060f31363d74 100644 (file)
  * In other words, skel = remove_invisible(nfd(remap_confusables(nfd(name)))).
  */
 
-typedef unsigned int __bitwise badname_t;
+typedef uint16_t __bitwise     badname_t;
 
 struct name_entry {
        struct name_entry       *next;
 
        /* NFKC normalized name */
        UChar                   *normstr;
-       size_t                  normstrlen;
 
        /* Unicode skeletonized name */
        UChar                   *skelstr;
-       size_t                  skelstrlen;
+
+       /* Lengths for normstr and skelstr */
+       int32_t                 normstrlen;
+       int32_t                 skelstrlen;
 
        xfs_ino_t               ino;
 
@@ -76,7 +78,7 @@ struct name_entry {
        badname_t               badflags;
 
        /* Raw dirent name */
-       size_t                  namelen;
+       uint16_t                namelen;
        char                    name[0];
 };
 #define NAME_ENTRY_SZ(nl)      (sizeof(struct name_entry) + 1 + \
@@ -345,6 +347,12 @@ name_entry_create(
        struct name_entry       *new_entry;
        size_t                  namelen = strlen(name);
 
+       /* should never happen */
+       if (namelen > UINT16_MAX) {
+               ASSERT(namelen <= UINT16_MAX);
+               return false;
+       }
+
        /* Create new entry */
        new_entry = calloc(NAME_ENTRY_SZ(namelen), 1);
        if (!new_entry)