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

* detect improper 0-length lists of variable-sized objects in SSZ reading
This commit is contained in:
tersec 2020-04-23 19:39:23 +00:00 committed by GitHub
parent 0079242457
commit 7bc18423fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 10 deletions

View File

@ -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
@ -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

View File

@ -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
@ -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

View File

@ -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

View File

@ -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)

View File

@ -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