@@ -2545,13 +2545,9 @@ struct ondisk_untracked_cache {
25452545 struct stat_data info_exclude_stat ;
25462546 struct stat_data excludes_file_stat ;
25472547 uint32_t dir_flags ;
2548- unsigned char info_exclude_sha1 [20 ];
2549- unsigned char excludes_file_sha1 [20 ];
2550- char exclude_per_dir [FLEX_ARRAY ];
25512548};
25522549
25532550#define ouc_offset (x ) offsetof(struct ondisk_untracked_cache, x)
2554- #define ouc_size (len ) (ouc_offset(exclude_per_dir) + len + 1)
25552551
25562552struct write_data {
25572553 int index ; /* number of written untracked_cache_dir */
@@ -2634,20 +2630,21 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
26342630 struct write_data wd ;
26352631 unsigned char varbuf [16 ];
26362632 int varint_len ;
2637- size_t len = strlen ( untracked -> exclude_per_dir ) ;
2633+ const unsigned hashsz = the_hash_algo -> rawsz ;
26382634
2639- FLEX_ALLOC_MEM ( ouc , exclude_per_dir , untracked -> exclude_per_dir , len );
2635+ ouc = xcalloc ( 1 , sizeof ( * ouc ) );
26402636 stat_data_to_disk (& ouc -> info_exclude_stat , & untracked -> ss_info_exclude .stat );
26412637 stat_data_to_disk (& ouc -> excludes_file_stat , & untracked -> ss_excludes_file .stat );
2642- hashcpy (ouc -> info_exclude_sha1 , untracked -> ss_info_exclude .oid .hash );
2643- hashcpy (ouc -> excludes_file_sha1 , untracked -> ss_excludes_file .oid .hash );
26442638 ouc -> dir_flags = htonl (untracked -> dir_flags );
26452639
26462640 varint_len = encode_varint (untracked -> ident .len , varbuf );
26472641 strbuf_add (out , varbuf , varint_len );
26482642 strbuf_addbuf (out , & untracked -> ident );
26492643
2650- strbuf_add (out , ouc , ouc_size (len ));
2644+ strbuf_add (out , ouc , sizeof (* ouc ));
2645+ strbuf_add (out , untracked -> ss_info_exclude .oid .hash , hashsz );
2646+ strbuf_add (out , untracked -> ss_excludes_file .oid .hash , hashsz );
2647+ strbuf_add (out , untracked -> exclude_per_dir , strlen (untracked -> exclude_per_dir ) + 1 );
26512648 FREE_AND_NULL (ouc );
26522649
26532650 if (!untracked -> root ) {
@@ -2834,6 +2831,9 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
28342831 int ident_len ;
28352832 ssize_t len ;
28362833 const char * exclude_per_dir ;
2834+ const unsigned hashsz = the_hash_algo -> rawsz ;
2835+ const unsigned offset = sizeof (struct ondisk_untracked_cache );
2836+ const unsigned exclude_per_dir_offset = offset + 2 * hashsz ;
28372837
28382838 if (sz <= 1 || end [-1 ] != '\0' )
28392839 return NULL ;
@@ -2845,23 +2845,23 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
28452845 ident = (const char * )next ;
28462846 next += ident_len ;
28472847
2848- if (next + ouc_size ( 0 ) > end )
2848+ if (next + exclude_per_dir_offset + 1 > end )
28492849 return NULL ;
28502850
28512851 uc = xcalloc (1 , sizeof (* uc ));
28522852 strbuf_init (& uc -> ident , ident_len );
28532853 strbuf_add (& uc -> ident , ident , ident_len );
28542854 load_oid_stat (& uc -> ss_info_exclude ,
28552855 next + ouc_offset (info_exclude_stat ),
2856- next + ouc_offset ( info_exclude_sha1 ) );
2856+ next + offset );
28572857 load_oid_stat (& uc -> ss_excludes_file ,
28582858 next + ouc_offset (excludes_file_stat ),
2859- next + ouc_offset ( excludes_file_sha1 ) );
2859+ next + offset + hashsz );
28602860 uc -> dir_flags = get_be32 (next + ouc_offset (dir_flags ));
2861- exclude_per_dir = (const char * )next + ouc_offset ( exclude_per_dir ) ;
2861+ exclude_per_dir = (const char * )next + exclude_per_dir_offset ;
28622862 uc -> exclude_per_dir = xstrdup (exclude_per_dir );
28632863 /* NUL after exclude_per_dir is covered by sizeof(*ouc) */
2864- next += ouc_size ( strlen (exclude_per_dir )) ;
2864+ next += exclude_per_dir_offset + strlen (exclude_per_dir ) + 1 ;
28652865 if (next >= end )
28662866 goto done2 ;
28672867
0 commit comments