@cryptotaxi247 / kubo / commits / 8fce0c416

validate data read from fsrefstore

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jan 30, 2017 at 00:48 UTC 8fce0c4161ba740bb32ac632e814dc9210567527
3 files changed +16 -16
filestore/fsrefstore.go
+12 -2
@@ -109,11 +109,21 @@ func (f *FileManager) Get(c *cid.Cid) (blocks.Block, error) {
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 +
121 return blocks.NewBlockWithCid(out, c)
122 }
123
124 func (f *FileManager) readDataObj(d *pb.DataObj) ([]byte, error) {
116 - abspath := filepath.Join(f.root, d.GetFilePath())
125 + p := filepath.FromSlash(d.GetFilePath())
126 + abspath := filepath.Join(f.root, p)
127
128 fi, err := os.Open(abspath)
129 if err != nil {
@@ -162,7 +172,7 @@ func (f *FileManager) putTo(b *posinfo.FilestoreNode, to putter) error {
172 return err
173 }
174
165 - dobj.FilePath = proto.String(p)
175 + dobj.FilePath = proto.String(filepath.ToSlash(p))
176 dobj.Offset = proto.Uint64(b.PosInfo.Offset)
177 dobj.Size_ = proto.Uint64(uint64(len(b.RawData())))
178
filestore/pb/dataobj.pb.go
+4 -12
@@ -23,11 +23,10 @@ var _ = fmt.Errorf
23 var _ = math.Inf
24
25 type DataObj struct {
26 - FilePath *string `protobuf:"bytes,1,opt,name=FilePath" json:"FilePath,omitempty"`
27 - Offset *uint64 `protobuf:"varint,2,opt,name=Offset" json:"Offset,omitempty"`
28 - Size_ *uint64 `protobuf:"varint,3,opt,name=Size" json:"Size,omitempty"`
29 - Modtime *float64 `protobuf:"fixed64,4,opt,name=Modtime" json:"Modtime,omitempty"`
30 - XXX_unrecognized []byte `json:"-"`
26 + FilePath *string `protobuf:"bytes,1,opt,name=FilePath" json:"FilePath,omitempty"`
27 + Offset *uint64 `protobuf:"varint,2,opt,name=Offset" json:"Offset,omitempty"`
28 + Size_ *uint64 `protobuf:"varint,3,opt,name=Size" json:"Size,omitempty"`
29 + XXX_unrecognized []byte `json:"-"`
30 }
31
32 func (m *DataObj) Reset() { *m = DataObj{} }
@@ -55,13 +54,6 @@ func (m *DataObj) GetSize_() uint64 {
54 return 0
55 }
56
58 -func (m *DataObj) GetModtime() float64 {
59 - if m != nil && m.Modtime != nil {
60 - return *m.Modtime
61 - }
62 - return 0
63 -}
64 -
57 func init() {
58 proto.RegisterType((*DataObj)(nil), "datastore.pb.DataObj")
59 }
filestore/pb/dataobj.proto
-2
@@ -4,6 +4,4 @@ message DataObj {
4 optional string FilePath = 1;
5 optional uint64 Offset = 2;
6 optional uint64 Size = 3;
7 -
8 - optional double Modtime = 4;
7 }