Skip to content
Snippets Groups Projects
Commit ba4d10f2 authored by capossele's avatar capossele
Browse files

:bug: checks meta_tx size

parent 8ce1871c
No related branches found
No related tags found
No related merge requests found
......@@ -56,8 +56,11 @@ func FromTrits(trits trinary.Trits) *MetaTransaction {
}
}
func FromBytes(bytes []byte) (result *MetaTransaction) {
func FromBytes(bytes []byte) (result *MetaTransaction, err error) {
trits := trinary.MustBytesToTrits(bytes)
if len(trits) < MARSHALED_TOTAL_SIZE {
return nil, fmt.Errorf("invalid size %v", len(trits))
}
result = FromTrits(trits[:MARSHALED_TOTAL_SIZE])
result.bytes = bytes
......
......@@ -47,7 +47,9 @@ func TestMetaTransaction_SettersGetters(t *testing.T) {
assert.Equal(t, tx.IsHead(), head)
assert.Equal(t, tx.IsTail(), tail)
assert.Equal(t, tx.GetTransactionType(), transactionType)
assert.Equal(t, tx.GetHash(), FromBytes(tx.GetBytes()).GetHash())
metaTx, err := FromBytes(tx.GetBytes())
require.NoError(t, err)
assert.Equal(t, tx.GetHash(), metaTx.GetHash())
assert.EqualValues(t, "KKDVHBENVLQUNO9WOWWEJPBBHUSYRSRKIMZWCFCDB9RYZKYWLAYWRIBRQETBFKE9TIVWQPCKFWAMCLCAV", tx.GetHash())
}
......
......@@ -42,8 +42,12 @@ func configureSolidifier() {
requestedTxs = NewUnsolidTxs()
gossip.Events.TransactionReceived.Attach(events.NewClosure(func(ev *gossip.TransactionReceivedEvent) {
metaTx := meta_transaction.FromBytes(ev.Data)
if err := metaTx.Validate(); err != nil {
metaTx, err := meta_transaction.FromBytes(ev.Data)
if err != nil {
log.Warnf("invalid transaction: %s", err)
return
}
if err = metaTx.Validate(); err != nil {
log.Warnf("invalid transaction: %s", err)
return
}
......
......@@ -131,7 +131,11 @@ func TestTangle(t *testing.T) {
// transactionReceived mocks the TransactionReceived event by allowing lower mwm
func transactionReceived(ev *gossip.TransactionReceivedEvent) {
metaTx := meta_transaction.FromBytes(ev.Data)
metaTx, err := meta_transaction.FromBytes(ev.Data)
if err != nil {
log.Warnf("invalid transaction: %s", err)
return
}
if metaTx.GetWeightMagnitude() < testMWM {
log.Warnf("invalid weight magnitude: %d / %d", metaTx.GetWeightMagnitude(), testMWM)
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment