fs: don't panic when using a too-short object ID to push
Previously, we'd panic when trying to slice into the object ID if the user provided a too-short object ID on the command line. Instead, let's fix this so we reject too-short object IDs with an error.
This commit is contained in:
parent
f529c87d5e
commit
3f4662b489
3
fs/fs.go
3
fs/fs.go
@ -65,6 +65,9 @@ func (f *Filesystem) ObjectExists(oid string, size int64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filesystem) ObjectPath(oid string) (string, error) {
|
func (f *Filesystem) ObjectPath(oid string) (string, error) {
|
||||||
|
if len(oid) < 4 {
|
||||||
|
return "", fmt.Errorf("too short object ID: %q", oid)
|
||||||
|
}
|
||||||
dir := f.localObjectDir(oid)
|
dir := f.localObjectDir(oid)
|
||||||
if err := tools.MkdirAll(dir, f); err != nil {
|
if err := tools.MkdirAll(dir, f); err != nil {
|
||||||
return "", fmt.Errorf("error trying to create local storage directory in %q: %s", dir, err)
|
return "", fmt.Errorf("error trying to create local storage directory in %q: %s", dir, err)
|
||||||
|
13
t/t-push.sh
13
t/t-push.sh
@ -820,3 +820,16 @@ begin_test "push custom reference"
|
|||||||
assert_server_object "$reponame" "$oid"
|
assert_server_object "$reponame" "$oid"
|
||||||
)
|
)
|
||||||
end_test
|
end_test
|
||||||
|
|
||||||
|
begin_test "push --object-id (invalid value)"
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
|
||||||
|
push_all_setup "everything"
|
||||||
|
|
||||||
|
git lfs push --object-id origin '' 2>&1 | tee push.log
|
||||||
|
git lfs push --object-id origin "${oid1:1:4}" 2>&1 | tee -a push.log
|
||||||
|
|
||||||
|
[ "$(grep -c 'too short object ID' push.log)" -eq 2 ]
|
||||||
|
)
|
||||||
|
end_test
|
||||||
|
Loading…
Reference in New Issue
Block a user