Commit d9092f16 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 13cd8cd9
...@@ -147,9 +147,6 @@ func (p *RowInfo) NEODecode(data []byte) (int, error) { ...@@ -147,9 +147,6 @@ func (p *RowInfo) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
p.CellList = make([]CellInfo, l) p.CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.CellList[i] a := &p.CellList[i]
...@@ -232,9 +229,6 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) { ...@@ -232,9 +229,6 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.Zzz = make(map[int32]map[int32]string, l) p.Zzz = make(map[int32]map[int32]string, l)
m := p.Zzz m := p.Zzz
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
...@@ -247,9 +241,6 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) { ...@@ -247,9 +241,6 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
v = make(map[int32]string, l) v = make(map[int32]string, l)
m := v m := v
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
...@@ -267,13 +258,9 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) { ...@@ -267,13 +258,9 @@ func (p *XXXTest) NEODecode(data []byte) (int, error) {
m[key] = string(data[:l]) m[key] = string(data[:l])
data = data[l:] data = data[l:]
} }
data = data[0:]
nread += 0
} }
} }
m[key] = v m[key] = v
data = data[0:]
nread += 0
} }
} }
return 0 + int(nread), nil return 0 + int(nread), nil
...@@ -518,9 +505,6 @@ func (p *AcceptIdentification) NEODecode(data []byte) (int, error) { ...@@ -518,9 +505,6 @@ func (p *AcceptIdentification) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[2:]) l := binary.BigEndian.Uint32(data[2:])
data = data[6:] data = data[6:]
nread += 6 nread += 6
if uint32(len(data)) < l {
goto overflow
}
p.KnownMasterList = make([]struct { p.KnownMasterList = make([]struct {
Address Address
UUID UUID UUID UUID
...@@ -745,9 +729,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -745,9 +729,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.RowList = make([]RowInfo, l) p.RowList = make([]RowInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.RowList[i] a := &p.RowList[i]
...@@ -759,9 +740,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -759,9 +740,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
...@@ -774,8 +752,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -774,8 +752,6 @@ func (p *AnswerPartitionTable) NEODecode(data []byte) (int, error) {
nread += 8 nread += 8
} }
} }
data = data[0:]
nread += 0
} }
} }
return 0 + int(nread), nil return 0 + int(nread), nil
...@@ -830,9 +806,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -830,9 +806,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.RowList = make([]RowInfo, l) p.RowList = make([]RowInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.RowList[i] a := &p.RowList[i]
...@@ -844,9 +817,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -844,9 +817,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
...@@ -859,8 +829,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -859,8 +829,6 @@ func (p *NotifyPartitionTable) NEODecode(data []byte) (int, error) {
nread += 8 nread += 8
} }
} }
data = data[0:]
nread += 0
} }
} }
return 0 + int(nread), nil return 0 + int(nread), nil
...@@ -901,9 +869,6 @@ func (p *PartitionChanges) NEODecode(data []byte) (int, error) { ...@@ -901,9 +869,6 @@ func (p *PartitionChanges) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.CellList = make([]struct { p.CellList = make([]struct {
Offset uint32 Offset uint32
UUID UUID UUID UUID
...@@ -1004,9 +969,6 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) { ...@@ -1004,9 +969,6 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.TidList = make([]struct{ UnfinishedTID Tid }, l) p.TidList = make([]struct{ UnfinishedTID Tid }, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.TidList[i] a := &p.TidList[i]
...@@ -1070,9 +1032,6 @@ func (p *AnswerLockedTransactions) NEODecode(data []byte) (int, error) { ...@@ -1070,9 +1032,6 @@ func (p *AnswerLockedTransactions) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.TidDict = make(map[Tid]Tid, l) p.TidDict = make(map[Tid]Tid, l)
m := p.TidDict m := p.TidDict
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
...@@ -1238,30 +1197,21 @@ func (p *FinishTransaction) NEODecode(data []byte) (int, error) { ...@@ -1238,30 +1197,21 @@ func (p *FinishTransaction) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.OIDList = make([]Oid, l) p.OIDList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OIDList[i] a := &p.OIDList[i]
if uint32(len(data)) < 8 { if uint32(len(data)) < 12 {
goto overflow goto overflow
} }
(*a) = Oid(binary.BigEndian.Uint64(data[0:])) (*a) = Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:] data = data[8:]
nread += 8 nread += 8
} }
if uint32(len(data)) < 4 {
goto overflow
}
} }
{ {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.CheckedList = make([]Oid, l) p.CheckedList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.CheckedList[i] a := &p.CheckedList[i]
...@@ -1399,9 +1349,6 @@ func (p *InvalidateObjects) NEODecode(data []byte) (int, error) { ...@@ -1399,9 +1349,6 @@ func (p *InvalidateObjects) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.OidList = make([]Oid, l) p.OidList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i] a := &p.OidList[i]
...@@ -1489,9 +1436,6 @@ func (p *AnswerGenerateOIDs) NEODecode(data []byte) (int, error) { ...@@ -1489,9 +1436,6 @@ func (p *AnswerGenerateOIDs) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.OidList = make([]Oid, l) p.OidList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i] a := &p.OidList[i]
...@@ -1586,22 +1530,16 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) { ...@@ -1586,22 +1530,16 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[37:]) l := binary.BigEndian.Uint32(data[37:])
data = data[41:] data = data[41:]
nread += 41 nread += 41
if uint32(len(data)) < l {
goto overflow
}
p.Data = make([]byte, l) p.Data = make([]byte, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.Data[i] a := &p.Data[i]
if uint32(len(data)) < 1 { if uint32(len(data)) < 18 {
goto overflow goto overflow
} }
(*a) = (data[0:])[0] (*a) = (data[0:])[0]
data = data[1:] data = data[1:]
nread += 1 nread += 1
} }
if uint32(len(data)) < 17 {
goto overflow
}
} }
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:])) p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:])) p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
...@@ -1739,9 +1677,6 @@ func (p *StoreTransaction) NEODecode(data []byte) (int, error) { ...@@ -1739,9 +1677,6 @@ func (p *StoreTransaction) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.OidList = make([]Oid, l) p.OidList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i] a := &p.OidList[i]
...@@ -1882,22 +1817,16 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) { ...@@ -1882,22 +1817,16 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[45:]) l := binary.BigEndian.Uint32(data[45:])
data = data[49:] data = data[49:]
nread += 49 nread += 49
if uint32(len(data)) < l {
goto overflow
}
p.Data = make([]byte, l) p.Data = make([]byte, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.Data[i] a := &p.Data[i]
if uint32(len(data)) < 1 { if uint32(len(data)) < 9 {
goto overflow goto overflow
} }
(*a) = (data[0:])[0] (*a) = (data[0:])[0]
data = data[1:] data = data[1:]
nread += 1 nread += 1
} }
if uint32(len(data)) < 8 {
goto overflow
}
} }
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:])) p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
return 8 + int(nread), nil return 8 + int(nread), nil
...@@ -1959,9 +1888,6 @@ func (p *AnswerTIDList) NEODecode(data []byte) (int, error) { ...@@ -1959,9 +1888,6 @@ func (p *AnswerTIDList) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.TIDList = make([]Tid, l) p.TIDList = make([]Tid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.TIDList[i] a := &p.TIDList[i]
...@@ -2034,9 +1960,6 @@ func (p *AnswerTIDListFrom) NEODecode(data []byte) (int, error) { ...@@ -2034,9 +1960,6 @@ func (p *AnswerTIDListFrom) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.TidList = make([]Tid, l) p.TidList = make([]Tid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.TidList[i] a := &p.TidList[i]
...@@ -2158,9 +2081,6 @@ func (p *AnswerTransactionInformation) NEODecode(data []byte) (int, error) { ...@@ -2158,9 +2081,6 @@ func (p *AnswerTransactionInformation) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[1:]) l := binary.BigEndian.Uint32(data[1:])
data = data[5:] data = data[5:]
nread += 5 nread += 5
if uint32(len(data)) < l {
goto overflow
}
p.OidList = make([]Oid, l) p.OidList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i] a := &p.OidList[i]
...@@ -2234,9 +2154,6 @@ func (p *AnswerObjectHistory) NEODecode(data []byte) (int, error) { ...@@ -2234,9 +2154,6 @@ func (p *AnswerObjectHistory) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.HistoryList = make([]struct { p.HistoryList = make([]struct {
Serial Tid Serial Tid
Size uint32 Size uint32
...@@ -2329,9 +2246,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) { ...@@ -2329,9 +2246,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[8:]) l := binary.BigEndian.Uint32(data[8:])
data = data[12:] data = data[12:]
nread += 12 nread += 12
if uint32(len(data)) < l {
goto overflow
}
p.RowList = make([]RowInfo, l) p.RowList = make([]RowInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.RowList[i] a := &p.RowList[i]
...@@ -2343,9 +2257,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) { ...@@ -2343,9 +2257,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
...@@ -2358,8 +2269,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) { ...@@ -2358,8 +2269,6 @@ func (p *AnswerPartitionList) NEODecode(data []byte) (int, error) {
nread += 8 nread += 8
} }
} }
data = data[0:]
nread += 0
} }
} }
return 0 + int(nread), nil return 0 + int(nread), nil
...@@ -2433,9 +2342,6 @@ func (p *AnswerNodeList) NEODecode(data []byte) (int, error) { ...@@ -2433,9 +2342,6 @@ func (p *AnswerNodeList) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.NodeList = make([]NodeInfo, l) p.NodeList = make([]NodeInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
...@@ -2518,9 +2424,6 @@ func (p *AddPendingNodes) NEODecode(data []byte) (int, error) { ...@@ -2518,9 +2424,6 @@ func (p *AddPendingNodes) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.UUIDList = make([]UUID, l) p.UUIDList = make([]UUID, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.UUIDList[i] a := &p.UUIDList[i]
...@@ -2566,9 +2469,6 @@ func (p *TweakPartitionTable) NEODecode(data []byte) (int, error) { ...@@ -2566,9 +2469,6 @@ func (p *TweakPartitionTable) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.UUIDList = make([]UUID, l) p.UUIDList = make([]UUID, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.UUIDList[i] a := &p.UUIDList[i]
...@@ -2630,9 +2530,6 @@ func (p *NotifyNodeInformation) NEODecode(data []byte) (int, error) { ...@@ -2630,9 +2530,6 @@ func (p *NotifyNodeInformation) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.NodeList = make([]NodeInfo, l) p.NodeList = make([]NodeInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
...@@ -2774,9 +2671,6 @@ func (p *ObjectUndoSerial) NEODecode(data []byte) (int, error) { ...@@ -2774,9 +2671,6 @@ func (p *ObjectUndoSerial) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[24:]) l := binary.BigEndian.Uint32(data[24:])
data = data[28:] data = data[28:]
nread += 28 nread += 28
if uint32(len(data)) < l {
goto overflow
}
p.OidList = make([]Oid, l) p.OidList = make([]Oid, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i] a := &p.OidList[i]
...@@ -2829,9 +2723,6 @@ func (p *AnswerObjectUndoSerial) NEODecode(data []byte) (int, error) { ...@@ -2829,9 +2723,6 @@ func (p *AnswerObjectUndoSerial) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.ObjectTIDDict = make(map[Oid]struct { p.ObjectTIDDict = make(map[Oid]struct {
CurrentSerial Tid CurrentSerial Tid
UndoSerial Tid UndoSerial Tid
...@@ -3035,9 +2926,6 @@ func (p *CheckReplicas) NEODecode(data []byte) (int, error) { ...@@ -3035,9 +2926,6 @@ func (p *CheckReplicas) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[0:]) l := binary.BigEndian.Uint32(data[0:])
data = data[4:] data = data[4:]
nread += 4 nread += 4
if uint32(len(data)) < l {
goto overflow
}
p.PartitionDict = make(map[uint32]UUID, l) p.PartitionDict = make(map[uint32]UUID, l)
m := p.PartitionDict m := p.PartitionDict
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
...@@ -3377,9 +3265,6 @@ func (p *PartitionCorrupted) NEODecode(data []byte) (int, error) { ...@@ -3377,9 +3265,6 @@ func (p *PartitionCorrupted) NEODecode(data []byte) (int, error) {
l := binary.BigEndian.Uint32(data[4:]) l := binary.BigEndian.Uint32(data[4:])
data = data[8:] data = data[8:]
nread += 8 nread += 8
if uint32(len(data)) < l {
goto overflow
}
p.CellList = make([]UUID, l) p.CellList = make([]UUID, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.CellList[i] a := &p.CellList[i]
......
...@@ -333,10 +333,10 @@ type decoder struct { ...@@ -333,10 +333,10 @@ type decoder struct {
bufCur Buffer bufCur Buffer
// current decode position in data. // current decode position in data.
// also = currently collected info for delayed emit of overflow check n int
// .num - position
// .exprv - XXX TODO // size that will be checked for overflow at current overflow check point
pos size overflowCheckSize size
commonCoder commonCoder
} }
...@@ -364,9 +364,9 @@ func (s *sizer) resultExpr() string { ...@@ -364,9 +364,9 @@ func (s *sizer) resultExpr() string {
func (s *sizer) generatedCode() string { func (s *sizer) generatedCode() string {
code := Buffer{} code := Buffer{}
// prologue // prologue
if s.recvName != "" { //if s.recvName != "" { XXX remove
code.emit("func (%s *%s) NEOEncodedLen() int {", s.recvName, s.typeName) code.emit("func (%s *%s) NEOEncodedLen() int {", s.recvName, s.typeName)
} //}
if s.varUsed["size"] { if s.varUsed["size"] {
code.emit("var %s int", s.var__("size")) code.emit("var %s int", s.var__("size"))
} }
...@@ -374,10 +374,10 @@ func (s *sizer) generatedCode() string { ...@@ -374,10 +374,10 @@ func (s *sizer) generatedCode() string {
code.Write(s.Bytes()) // XXX -> s.buf.Bytes() ? code.Write(s.Bytes()) // XXX -> s.buf.Bytes() ?
// epilogue // epilogue
if s.recvName != "" { //if s.recvName != "" { XXX remove
code.emit("return %v", s.resultExpr()) code.emit("return %v", s.resultExpr())
code.emit("}\n") code.emit("}\n")
} //}
return code.String() return code.String()
} }
...@@ -403,17 +403,42 @@ func (d *decoder) emit(format string, a ...interface{}) { ...@@ -403,17 +403,42 @@ func (d *decoder) emit(format string, a ...interface{}) {
} }
// XXX place? // XXX place?
func (d *decoder) flushOverflow() { // data <- data[pos:]
if !d.pos.IsZero() { // add overflow checkpoint XXX
d.buf.emit("if uint32(len(data)) < %v { goto overflow }", &d.pos) // pos <- 0
func (d *decoder) resetPos() {
if d.n != 0 {
d.emit("data = data[%v:]", d.n)
d.emit("%v += %v", d.var_("nread"), d.n)
}
d.n = 0
}
// XXX place?
// mark current place for delayed insertion of overflow check code
//
// delayed: because we go forward in decode path scanning ahead as far as we
// can - until first variable-size encoded something, and then insert checking
// condition for accumulated size to here-marked overflow checkpoint.
//
// so overflowCheckpoint does:
// 1. emit overflow checking code for previous overflow checkpoint
// 2. mark current place as next overflow checkpoint to eventually emit
func (d *decoder) overflowCheckpoint() {
//d.buf.emit("// overflow check point")
if !d.overflowCheckSize.IsZero() {
d.buf.emit("if uint32(len(data)) < %v { goto overflow }", &d.overflowCheckSize)
} }
d.overflowCheckSize = size{} // zero
d.buf.Write(d.bufCur.Bytes()) d.buf.Write(d.bufCur.Bytes())
d.bufCur.Reset() d.bufCur.Reset()
// TODO
} }
func (d *decoder) generatedCode() string { func (d *decoder) generatedCode() string {
d.flushOverflow() d.overflowCheckpoint()
code := Buffer{} code := Buffer{}
// prologue // prologue
...@@ -427,7 +452,7 @@ func (d *decoder) generatedCode() string { ...@@ -427,7 +452,7 @@ func (d *decoder) generatedCode() string {
code.Write(d.buf.Bytes()) code.Write(d.buf.Bytes())
// epilogue // epilogue
retexpr := fmt.Sprintf("%v", d.pos.num) retexpr := fmt.Sprintf("%v", d.n)
if d.varUsed["nread"] { if d.varUsed["nread"] {
retexpr += fmt.Sprintf(" + int(%v)", d.var__("nread")) retexpr += fmt.Sprintf(" + int(%v)", d.var__("nread"))
} }
...@@ -465,9 +490,10 @@ func (e *encoder) genBasic(path string, typ *types.Basic, userType types.Type) { ...@@ -465,9 +490,10 @@ func (e *encoder) genBasic(path string, typ *types.Basic, userType types.Type) {
func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Type) { func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Type) {
basic := basicTypes[typ.Kind()] basic := basicTypes[typ.Kind()]
//d.emit("if len(data) < %v { goto overflow }", d.n + basic.wireSize) //d.emit("if len(data) < %v { goto overflow }", d.n + basic.wireSize)
dataptr := fmt.Sprintf("data[%v:]", d.pos.num) dataptr := fmt.Sprintf("data[%v:]", d.n)
decoded := fmt.Sprintf(basic.decode, dataptr) decoded := fmt.Sprintf(basic.decode, dataptr)
d.pos.Add(basic.wireSize) d.n += basic.wireSize
d.overflowCheckSize.Add(basic.wireSize)
if userType != nil && userType != typ { if userType != nil && userType != typ {
// userType is a named type over some basic, like // userType is a named type over some basic, like
// type ClusterState int32 // type ClusterState int32
...@@ -502,13 +528,19 @@ func (e *encoder) genStrBytes(path string) { ...@@ -502,13 +528,19 @@ func (e *encoder) genStrBytes(path string) {
func (d *decoder) genStrBytes(assignto string) { func (d *decoder) genStrBytes(assignto string) {
d.emit("{") d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil) d.genBasic("l:", types.Typ[types.Uint32], nil)
/*
d.emit("data = data[%v:]", d.pos.num) d.emit("data = data[%v:]", d.pos.num)
d.emit("%v += %v + l", d.var_("nread"), d.pos.num) d.emit("%v += %v + l", d.var_("nread"), d.pos.num)
*/
//d.emit("if uint32(len(data)) < l { goto overflow }") //d.resetPos()
d.flushOverflow() d.emit("data = data[%v:]", d.n)
d.pos = size{} // zero d.emit("%v += %v + l", d.var_("nread"), d.n)
d.pos.AddExpr("l") d.n = 0
d.overflowCheckpoint()
d.overflowCheckSize.AddExpr("l")
d.emit("%v= string(data[:l])", assignto) d.emit("%v= string(data[:l])", assignto)
d.emit("data = data[l:]") d.emit("data = data[l:]")
...@@ -574,12 +606,17 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) { ...@@ -574,12 +606,17 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) {
func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object) { func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object) {
d.emit("{") d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil) d.genBasic("l:", types.Typ[types.Uint32], nil)
/*
d.emit("data = data[%v:]", d.pos.num) d.emit("data = data[%v:]", d.pos.num)
d.emit("%v += %v", d.var_("nread"), d.pos.num) d.emit("%v += %v", d.var_("nread"), d.pos.num)
d.flushOverflow() d.flushOverflow()
d.pos = size{} // zero d.pos = size{} // zero
d.pos.AddExpr("l") */
d.resetPos()
//d.overflowCheckpoint()
//d.pos.AddExpr("l") // FIXME l*sizeof(elem)
/* /*
elemSize, elemFixed := typeSizeFixed(typ.Elem()) elemSize, elemFixed := typeSizeFixed(typ.Elem())
...@@ -595,21 +632,28 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object) ...@@ -595,21 +632,28 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
d.emit("for i := 0; uint32(i) < l; i++ {") d.emit("for i := 0; uint32(i) < l; i++ {")
d.emit("a := &%s[i]", assignto) d.emit("a := &%s[i]", assignto)
/*
d.flushOverflow() d.flushOverflow()
d.pos = size{} // zero d.pos = size{} // zero
*/
d.overflowCheckpoint()
d.resetPos()
codegenType("(*a)", typ.Elem(), obj, d) codegenType("(*a)", typ.Elem(), obj, d)
/*
d.emit("data = data[%v:]", d.pos.num) // FIXME wrt slice of slice ? d.emit("data = data[%v:]", d.pos.num) // FIXME wrt slice of slice ?
d.emit("%v += %v", d.var_("nread"), d.pos.num) d.emit("%v += %v", d.var_("nread"), d.pos.num)
*/
d.resetPos()
d.emit("}") d.emit("}")
d.flushOverflow() //d.overflowCheckpoint()
d.pos = size{} // zero //d.resetPos()
//d.emit("%v= string(data[:l])", assignto) //d.emit("%v= string(data[:l])", assignto)
d.emit("}") d.emit("}")
//d.n = 0
} }
// generate code to encode/decode map // generate code to encode/decode map
...@@ -674,12 +718,17 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -674,12 +718,17 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d.emit("{") d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil) d.genBasic("l:", types.Typ[types.Uint32], nil)
/*
d.emit("data = data[%v:]", d.pos.num) d.emit("data = data[%v:]", d.pos.num)
d.emit("%v += %v", d.var_("nread"), d.pos.num) d.emit("%v += %v", d.var_("nread"), d.pos.num)
d.flushOverflow() d.flushOverflow()
d.pos = size{} // zero d.pos = size{} // zero
d.pos.AddExpr("l") */
d.overflowCheckpoint()
d.resetPos()
//d.pos.AddExpr("l")
d.emit("%v= make(%v, l)", assignto, typeName(typ)) d.emit("%v= make(%v, l)", assignto, typeName(typ))
// TODO size check // TODO size check
...@@ -688,8 +737,9 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { ...@@ -688,8 +737,9 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d.emit("m := %v", assignto) d.emit("m := %v", assignto)
d.emit("for i := 0; uint32(i) < l; i++ {") d.emit("for i := 0; uint32(i) < l; i++ {")
d.flushOverflow() d.overflowCheckpoint()
d.pos = size{} // zero d.resetPos()
codegenType("key:", typ.Key(), obj, d) codegenType("key:", typ.Key(), obj, d)
switch typ.Elem().Underlying().(type) { switch typ.Elem().Underlying().(type) {
...@@ -705,12 +755,11 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { ...@@ -705,12 +755,11 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d.emit("m[key] = v") d.emit("m[key] = v")
} }
d.emit("data = data[%v:]", d.pos.num) // FIXME wrt map of map ? d.resetPos()
d.emit("%v += %v", d.var_("nread"), d.pos.num)
d.emit("}") d.emit("}")
d.flushOverflow() d.overflowCheckpoint()
d.pos = size{} // zero d.resetPos()
//d.emit("%v= string(data[:l])", assignto) //d.emit("%v= string(data[:l])", assignto)
d.emit("}") d.emit("}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment