@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"os"
12
12
"path/filepath"
13
+ "regexp"
13
14
"strings"
14
15
15
16
"github.com/Masterminds/semver"
@@ -117,6 +118,10 @@ func (bs *baseVCSSource) exportRevisionTo(ctx context.Context, r Revision, to st
117
118
return fs .CopyDir (bs .repo .LocalPath (), to )
118
119
}
119
120
121
+ var (
122
+ gitHashRE = regexp .MustCompile (`^[a-f0-9]{40}$` )
123
+ )
124
+
120
125
// gitSource is a generic git repository implementation that should work with
121
126
// all standard git remotes.
122
127
type gitSource struct {
@@ -238,6 +243,10 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
238
243
return nil
239
244
}
240
245
246
+ func (s * gitSource ) isValidHash (hash []byte ) bool {
247
+ return gitHashRE .Match (hash )
248
+ }
249
+
241
250
func (s * gitSource ) listVersions (ctx context.Context ) (vlist []PairedVersion , err error ) {
242
251
r := s .repo
243
252
@@ -298,6 +307,13 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
298
307
vlist = make ([]PairedVersion , len (all ))
299
308
for _ , pair := range all {
300
309
var v PairedVersion
310
+ // Valid `git ls-remote` output should start with hash, be at least
311
+ // 45 chars long and 40th character should be '\t'
312
+ //
313
+ // See: https://github.com/golang/dep/pull/1160#issuecomment-328843519
314
+ if len (pair ) < 45 || pair [40 ] != '\t' || ! s .isValidHash (pair [:40 ]) {
315
+ continue
316
+ }
301
317
if string (pair [41 :]) == "HEAD" {
302
318
// If HEAD is present, it's always first
303
319
headrev = Revision (pair [:40 ])
0 commit comments