Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect improper 0-length lists of variable-sized objects in SSZ reading #928

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ OK: 84/87 Fail: 3/87 Skip: 0/87
+ Iterators test OK
+ Peer lifetime test OK
+ Safe/Clear test OK
+ Score check test OK
+ addPeer() test OK
+ addPeerNoWait() test OK
+ deletePeer() test OK
```
OK: 9/9 Fail: 0/9 Skip: 0/9
OK: 10/10 Fail: 0/10 Skip: 0/10
## SSZ dynamic navigator
```diff
+ navigating fields OK
Expand Down Expand Up @@ -229,4 +230,4 @@ OK: 4/4 Fail: 0/4 Skip: 0/4
OK: 8/8 Fail: 0/8 Skip: 0/8

---TOTAL---
OK: 140/143 Fail: 3/143 Skip: 0/143
OK: 141/144 Fail: 3/144 Skip: 0/144
5 changes: 3 additions & 2 deletions AllTests-minimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ OK: 84/87 Fail: 3/87 Skip: 0/87
+ Iterators test OK
+ Peer lifetime test OK
+ Safe/Clear test OK
+ Score check test OK
+ addPeer() test OK
+ addPeerNoWait() test OK
+ deletePeer() test OK
```
OK: 9/9 Fail: 0/9 Skip: 0/9
OK: 10/10 Fail: 0/10 Skip: 0/10
## SSZ dynamic navigator
```diff
+ navigating fields OK
Expand Down Expand Up @@ -256,4 +257,4 @@ OK: 4/4 Fail: 0/4 Skip: 0/4
OK: 8/8 Fail: 0/8 Skip: 0/8

---TOTAL---
OK: 155/158 Fail: 3/158 Skip: 0/158
OK: 156/159 Fail: 3/159 Skip: 0/159
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ yourAURmanager -S base-devel pcre-static

### MacOS

Assuming you use [Homebrew](https://brew.sh/) to manage packages
Assuming you use [Homebrew](https://brew.sh/) to manage packages:

```sh
brew install pcre
Expand Down
7 changes: 7 additions & 0 deletions beacon_chain/ssz/bytes_reader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ func readSszValue*(input: openarray[byte], T: type): T {.raisesssz.} =
trs "GOT OFFSET ", offset
let resultLen = offset div offsetSize
trs "LEN ", resultLen

if resultLen == 0:
# If there are too many elements, other constraints detect problems
# (not monotonically increasing, past end of input, or last element
# not matching up with its nextOffset properly)
raise newException(MalformedSszError, "SSZ list incorrectly encoded of zero length")

result.setOutputSize resultLen
for i in 1 ..< resultLen:
let nextOffset = readOffset(i * offsetSize)
Expand Down
5 changes: 0 additions & 5 deletions beacon_chain/state_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
# areas. The entry point is `state_transition` which is at the bottom of the file!
#
# General notes about the code (TODO):
# * It's inefficient - we quadratically copy, allocate and iterate when there
# are faster options
# * Weird styling - the sections taken from the spec use python styling while
# the others use NEP-1 - helps grepping identifiers in spec
# * We mix procedural and functional styles for no good reason, except that the
# spec does so also.
# * There are likely lots of bugs.
# * For indices, we get a mix of uint64, ValidatorIndex and int - this is currently
# swept under the rug with casts
# * The spec uses uint64 for data types, but functions in the spec often assume
# signed bigint semantics - under- and overflows ensue
# * Sane error handling is missing in most cases (yay, we'll get the chance to
# debate exceptions again!)
# When updating the code, add TODO sections to mark where there are clear
Expand Down