@@ -10,6 +10,7 @@ import (
1010 "fmt"
1111 "os"
1212 "path/filepath"
13+ "regexp"
1314 "strings"
1415
1516 "github.com/Masterminds/semver"
@@ -117,6 +118,10 @@ func (bs *baseVCSSource) exportRevisionTo(ctx context.Context, r Revision, to st
117118 return fs .CopyDir (bs .repo .LocalPath (), to )
118119}
119120
121+ var (
122+ gitHashRE = regexp .MustCompile (`^[a-f0-9]{40}$` )
123+ )
124+
120125// gitSource is a generic git repository implementation that should work with
121126// all standard git remotes.
122127type gitSource struct {
@@ -238,6 +243,10 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
238243 return nil
239244}
240245
246+ func (s * gitSource ) isValidHash (hash []byte ) bool {
247+ return gitHashRE .Match (hash )
248+ }
249+
241250func (s * gitSource ) listVersions (ctx context.Context ) (vlist []PairedVersion , err error ) {
242251 r := s .repo
243252
@@ -298,6 +307,13 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
298307 vlist = make ([]PairedVersion , len (all ))
299308 for _ , pair := range all {
300309 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+ }
301317 if string (pair [41 :]) == "HEAD" {
302318 // If HEAD is present, it's always first
303319 headrev = Revision (pair [:40 ])
0 commit comments