mirror of
https://github.com/git/git.git
synced 2024-11-08 12:59:54 +01:00
Merge branch 'tb/attr-limits' into maint-2.45
The maximum size of attribute files is enforced more consistently. * tb/attr-limits: attr.c: move ATTR_MAX_FILE_SIZE check into read_attr_from_buf()
This commit is contained in:
commit
6840423c6f
19
attr.c
19
attr.c
@ -765,8 +765,8 @@ static struct attr_stack *read_attr_from_file(const char *path, unsigned flags)
|
||||
return res;
|
||||
}
|
||||
|
||||
static struct attr_stack *read_attr_from_buf(char *buf, const char *path,
|
||||
unsigned flags)
|
||||
static struct attr_stack *read_attr_from_buf(char *buf, size_t length,
|
||||
const char *path, unsigned flags)
|
||||
{
|
||||
struct attr_stack *res;
|
||||
char *sp;
|
||||
@ -774,6 +774,11 @@ static struct attr_stack *read_attr_from_buf(char *buf, const char *path,
|
||||
|
||||
if (!buf)
|
||||
return NULL;
|
||||
if (length >= ATTR_MAX_FILE_SIZE) {
|
||||
warning(_("ignoring overly large gitattributes blob '%s'"), path);
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CALLOC_ARRAY(res, 1);
|
||||
for (sp = buf; *sp;) {
|
||||
@ -813,7 +818,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return read_attr_from_buf(buf, path, flags);
|
||||
return read_attr_from_buf(buf, sz, path, flags);
|
||||
}
|
||||
|
||||
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,
|
||||
stack = read_attr_from_blob(istate, &istate->cache[sparse_dir_pos]->oid, relative_path, flags);
|
||||
} else {
|
||||
buf = read_blob_data_from_index(istate, path, &size);
|
||||
if (!buf)
|
||||
return NULL;
|
||||
if (size >= ATTR_MAX_FILE_SIZE) {
|
||||
warning(_("ignoring overly large gitattributes blob '%s'"), path);
|
||||
return NULL;
|
||||
}
|
||||
stack = read_attr_from_buf(buf, path, flags);
|
||||
stack = read_attr_from_buf(buf, size, path, flags);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
@ -578,6 +578,16 @@ test_expect_success EXPENSIVE 'large attributes file ignored in index' '
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success EXPENSIVE 'large attributes blob ignored' '
|
||||
test_when_finished "git update-index --remove .gitattributes" &&
|
||||
blob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null | git hash-object -w --stdin) &&
|
||||
git update-index --add --cacheinfo 100644,$blob,.gitattributes &&
|
||||
tree="$(git write-tree)" &&
|
||||
git check-attr --cached --all --source="$tree" path >/dev/null 2>err &&
|
||||
echo "warning: ignoring overly large gitattributes blob ${SQ}.gitattributes${SQ}" >expect &&
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success 'builtin object mode attributes work (dir and regular paths)' '
|
||||
>normal &&
|
||||
attr_check_object_mode normal 100644 &&
|
||||
|
Loading…
Reference in New Issue
Block a user