@@ -85,9 +85,12 @@ type link struct {
85
85
86
86
var oidRegExp = regexp .MustCompile (`^[A-Fa-f0-9]+$` )
87
87
88
+ func isOidValid (oid string ) bool {
89
+ return oidRegExp .MatchString (oid )
90
+ }
91
+
88
92
// ObjectOidHandler is the main request routing entry point into LFS server functions
89
93
func ObjectOidHandler (ctx * context.Context ) {
90
-
91
94
if ! setting .LFS .StartServer {
92
95
writeStatus (ctx , 404 )
93
96
return
@@ -110,6 +113,11 @@ func ObjectOidHandler(ctx *context.Context) {
110
113
}
111
114
112
115
func getAuthenticatedRepoAndMeta (ctx * context.Context , rv * RequestVars , requireWrite bool ) (* models.LFSMetaObject , * models.Repository ) {
116
+ if ! isOidValid (rv .Oid ) {
117
+ writeStatus (ctx , 404 )
118
+ return nil , nil
119
+ }
120
+
113
121
repository , err := models .GetRepositoryByOwnerAndName (rv .User , rv .Repo )
114
122
if err != nil {
115
123
log .Debug ("Could not find repository: %s/%s - %s" , rv .User , rv .Repo , err )
@@ -222,7 +230,7 @@ func PostHandler(ctx *context.Context) {
222
230
return
223
231
}
224
232
225
- if ! oidRegExp . MatchString (rv .Oid ) {
233
+ if ! isOidValid (rv .Oid ) {
226
234
writeStatus (ctx , 404 )
227
235
return
228
236
}
@@ -249,7 +257,6 @@ func PostHandler(ctx *context.Context) {
249
257
250
258
// BatchHandler provides the batch api
251
259
func BatchHandler (ctx * context.Context ) {
252
-
253
260
if ! setting .LFS .StartServer {
254
261
writeStatus (ctx , 404 )
255
262
return
@@ -266,6 +273,10 @@ func BatchHandler(ctx *context.Context) {
266
273
267
274
// Create a response object
268
275
for _ , object := range bv .Objects {
276
+ if ! isOidValid (object .Oid ) {
277
+ continue
278
+ }
279
+
269
280
repository , err := models .GetRepositoryByOwnerAndName (object .User , object .Repo )
270
281
271
282
if err != nil {
@@ -292,12 +303,10 @@ func BatchHandler(ctx *context.Context) {
292
303
continue
293
304
}
294
305
295
- if oidRegExp .MatchString (object .Oid ) {
296
- // Object is not found
297
- meta , err = models .NewLFSMetaObject (& models.LFSMetaObject {Oid : object .Oid , Size : object .Size , RepositoryID : repository .ID })
298
- if err == nil {
299
- responseObjects = append (responseObjects , Represent (object , meta , meta .Existing , ! contentStore .Exists (meta )))
300
- }
306
+ // Object is not found
307
+ meta , err = models .NewLFSMetaObject (& models.LFSMetaObject {Oid : object .Oid , Size : object .Size , RepositoryID : repository .ID })
308
+ if err == nil {
309
+ responseObjects = append (responseObjects , Represent (object , meta , meta .Existing , ! contentStore .Exists (meta )))
301
310
}
302
311
}
303
312
0 commit comments