Skip to content

Commit

Permalink
Merge pull request #615 from FactomProject/FD-740_smart_unmarshal_limits
Browse files Browse the repository at this point in the history
fixed limit on fblock to handle possible empty coinbase transactions
  • Loading branch information
factom-clay committed Nov 20, 2018
2 parents 20b24c2 + f5d6c69 commit 4149244
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions common/directoryBlock/directoryBlock.go
Expand Up @@ -282,13 +282,12 @@ func (e *DirectoryBlock) String() string {
out.WriteString(fmt.Sprintf("%20s %v\n", "fullhash:", fh.String()))

out.WriteString(e.GetHeader().String())
out.WriteString("entries: \n")
out.WriteString("entries:\n")
for i, entry := range e.DBEntries {
out.WriteString(fmt.Sprintf("%5d %s", i, entry.String()))
}

return (string)(out.DeepCopyBytes())

}

func (b *DirectoryBlock) MarshalBinary() (rval []byte, err error) {
Expand Down
17 changes: 8 additions & 9 deletions common/factoid/fblock.go
Expand Up @@ -346,18 +346,17 @@ func (b *FBlock) UnmarshalBinaryData(data []byte) ([]byte, error) {
return nil, err
}

// txLimit is the maximum number of transactions (min 78 bytes) that could
// fit into the remaining unread portion of the buffer.
// txLimit is the maximum number of transactions (min 20 bytes for an empty
// coinbase tx) that could fit into the unread portion of the buffer.
l := buf.Len()
txLimit := uint32(l / 78)
txLimit := uint32(l / 20)

if txCount > txLimit {
//return nil, fmt.Errorf(
// "Error: FBlock.Unmarshal: transaction count %d higher than space "+
// "in body %d (uint underflow?)",
// txCount, txLimit,
//)
fmt.Println("Got here", txCount, txLimit)
return nil, fmt.Errorf(
"Error: FBlock.Unmarshal: transaction count %d higher than space "+
"in body %d (uint underflow?)",
txCount, txLimit,
)
}

b.Transactions = make([]interfaces.ITransaction, int(txCount), int(txCount))
Expand Down

0 comments on commit 4149244

Please sign in to comment.