This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) {
6161 c .actualSize += objSize
6262 for c .actualSize > c .MaxSize {
6363 last := c .ll .Back ()
64+ if last == nil {
65+ c .actualSize = 0
66+ break
67+ }
68+
6469 lastObj := last .Value .(plumbing.EncodedObject )
6570 lastSize := FileSize (lastObj .Size ())
6671
Original file line number Diff line number Diff line change @@ -153,6 +153,19 @@ func (s *ObjectSuite) TestDefaultLRU(c *C) {
153153 c .Assert (defaultLRU .MaxSize , Equals , DefaultMaxSize )
154154}
155155
156+ func (s * ObjectSuite ) TestObjectUpdateOverflow (c * C ) {
157+ o := NewObjectLRU (9 * Byte )
158+
159+ a1 := newObject (s .aObject .Hash ().String (), 9 * Byte )
160+ a2 := newObject (s .aObject .Hash ().String (), 1 * Byte )
161+ b := newObject (s .bObject .Hash ().String (), 1 * Byte )
162+
163+ o .Put (a1 )
164+ a1 .SetSize (- 5 )
165+ o .Put (a2 )
166+ o .Put (b )
167+ }
168+
156169type dummyObject struct {
157170 hash plumbing.Hash
158171 size FileSize
@@ -169,6 +182,6 @@ func (d *dummyObject) Hash() plumbing.Hash { return d.hash }
169182func (* dummyObject ) Type () plumbing.ObjectType { return plumbing .InvalidObject }
170183func (* dummyObject ) SetType (plumbing.ObjectType ) {}
171184func (d * dummyObject ) Size () int64 { return int64 (d .size ) }
172- func (* dummyObject ) SetSize (s int64 ) { }
185+ func (d * dummyObject ) SetSize (s int64 ) { d . size = FileSize ( s ) }
173186func (* dummyObject ) Reader () (io.ReadCloser , error ) { return nil , nil }
174187func (* dummyObject ) Writer () (io.WriteCloser , error ) { return nil , nil }
You can’t perform that action at this time.
0 commit comments