Skip to content

Commit 4d66123

Browse files
ehildenbrv-jenkins
authored andcommitted
data.md: handle the case where non-even length byte array is passed in (#598)
1 parent 0ef8fd6 commit 4d66123

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

data.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,11 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
814814
// -------------------------------------------------------------
815815
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
816816
rule #parseHexBytes("") => .ByteArray
817-
rule #parseHexBytes(S) => Int2Bytes(1, #parseHexWord(substrString(S, 0, 2)), BE) +Bytes #parseHexBytes(substrString(S, 2, lengthString(S))) requires lengthString(S) >=Int 2
817+
rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
818+
requires notBool lengthString(S) modInt 2 ==Int 0
819+
rule #parseHexBytes(S) => Int2Bytes(1, #parseHexWord(substrString(S, 0, 2)), BE) +Bytes #parseHexBytes(substrString(S, 2, lengthString(S)))
820+
requires lengthString(S) modInt 2 ==Int 0
821+
andBool lengthString(S) >Int 0
818822
819823
rule #parseByteStackRaw(S) => String2Bytes(S)
820824
```
@@ -826,7 +830,11 @@ These parsers can interperet hex-encoded strings as `Int`s, `ByteArray`s, and `M
826830
// -------------------------------------------------------------
827831
rule #parseByteStack(S) => #parseHexBytes(replaceAll(S, "0x", ""))
828832
rule #parseHexBytes("") => .WordStack
829-
rule #parseHexBytes(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytes(substrString(S, 2, lengthString(S))) requires lengthString(S) >=Int 2
833+
rule #parseHexBytes(S) => #parseHexBytes("0" +String S)
834+
requires notBool lengthString(S) modInt 2 ==Int 0
835+
rule #parseHexBytes(S) => #parseHexWord(substrString(S, 0, 2)) : #parseHexBytes(substrString(S, 2, lengthString(S)))
836+
requires lengthString(S) modInt 2 ==Int 0
837+
andBool lengthString(S) >Int 0
830838
831839
rule #parseByteStackRaw(S) => ordChar(substrString(S, 0, 1)) : #parseByteStackRaw(substrString(S, 1, lengthString(S))) requires lengthString(S) >=Int 1
832840
rule #parseByteStackRaw("") => .WordStack

0 commit comments

Comments
 (0)