@cryptotaxi247 / kubo / commits / 459a4b3d7

Move block verification into readDataObj.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Feb 3, 2017 at 16:21 UTC 459a4b3d7214809bc70d48a126f8504ace60d797
1 file changed +12 -11
filestore/fsrefstore.go
+12 -11
@@ -104,24 +104,16 @@ func (f *FileManager) Get(c *cid.Cid) (blocks.Block, error) {
104 return nil, err
105 }
106
107 - out, err := f.readDataObj(&dobj)
107 + out, err := f.readDataObj(c, &dobj)
108 if err != nil {
109 return nil, err
110 }
111
112 - outcid, err := c.Prefix().Sum(out)
113 - if err != nil {
114 - return nil, err
115 - }
116 -
117 - if !c.Equals(outcid) {
118 - return nil, &CorruptReferenceError{fmt.Errorf("data in file did not match. %s offset %d", dobj.GetFilePath(), dobj.GetOffset())}
119 - }
120 -
112 return blocks.NewBlockWithCid(out, c)
113 }
114
124 -func (f *FileManager) readDataObj(d *pb.DataObj) ([]byte, error) {
115 +// reads and verifies the block
116 +func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
117 p := filepath.FromSlash(d.GetFilePath())
118 abspath := filepath.Join(f.root, p)
119
@@ -142,6 +134,15 @@ func (f *FileManager) readDataObj(d *pb.DataObj) ([]byte, error) {
134 return nil, &CorruptReferenceError{err}
135 }
136
137 + outcid, err := c.Prefix().Sum(outbuf)
138 + if err != nil {
139 + return nil, err
140 + }
141 +
142 + if !c.Equals(outcid) {
143 + return nil, &CorruptReferenceError{fmt.Errorf("data in file did not match. %s offset %d", d.GetFilePath(), d.GetOffset())}
144 + }
145 +
146 return outbuf, nil
147 }
148