@@ -765,15 +765,20 @@ static struct attr_stack *read_attr_from_file(const char *path, unsigned flags)
765
765
return res ;
766
766
}
767
767
768
- static struct attr_stack * read_attr_from_buf (char * buf , const char * path ,
769
- unsigned flags )
768
+ static struct attr_stack * read_attr_from_buf (char * buf , size_t length ,
769
+ const char * path , unsigned flags )
770
770
{
771
771
struct attr_stack * res ;
772
772
char * sp ;
773
773
int lineno = 0 ;
774
774
775
775
if (!buf )
776
776
return NULL ;
777
+ if (length >= ATTR_MAX_FILE_SIZE ) {
778
+ warning (_ ("ignoring overly large gitattributes blob '%s'" ), path );
779
+ free (buf );
780
+ return NULL ;
781
+ }
777
782
778
783
CALLOC_ARRAY (res , 1 );
779
784
for (sp = buf ; * sp ;) {
@@ -813,7 +818,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
813
818
return NULL ;
814
819
}
815
820
816
- return read_attr_from_buf (buf , path , flags );
821
+ return read_attr_from_buf (buf , sz , path , flags );
817
822
}
818
823
819
824
static struct attr_stack * read_attr_from_index (struct index_state * istate ,
@@ -860,13 +865,7 @@ static struct attr_stack *read_attr_from_index(struct index_state *istate,
860
865
stack = read_attr_from_blob (istate , & istate -> cache [sparse_dir_pos ]-> oid , relative_path , flags );
861
866
} else {
862
867
buf = read_blob_data_from_index (istate , path , & size );
863
- if (!buf )
864
- return NULL ;
865
- if (size >= ATTR_MAX_FILE_SIZE ) {
866
- warning (_ ("ignoring overly large gitattributes blob '%s'" ), path );
867
- return NULL ;
868
- }
869
- stack = read_attr_from_buf (buf , path , flags );
868
+ stack = read_attr_from_buf (buf , size , path , flags );
870
869
}
871
870
return stack ;
872
871
}
0 commit comments