diff --git a/implementations/javascript/src/codec.js b/implementations/javascript/src/codec.js index 9b265cd..53c1cb5 100644 --- a/implementations/javascript/src/codec.js +++ b/implementations/javascript/src/codec.js @@ -138,6 +138,7 @@ class Decoder { mapFromArray(vs) { return Map().withMutations((m) => { + if (vs.length % 2) throw new DecodeError("Missing dictionary value"); for (let i = 0; i < vs.length; i += 2) { m.set(vs[i], vs[i+1]); } diff --git a/implementations/python/preserves/preserves.py b/implementations/python/preserves/preserves.py index bbab159..43e6d2e 100644 --- a/implementations/python/preserves/preserves.py +++ b/implementations/python/preserves/preserves.py @@ -166,7 +166,10 @@ class ImmutableDict(dict): try: while True: k = next(i) - v = next(i) + try: + v = next(i) + except StopIteration: + raise DecodeError("Missing dictionary value") result_proxy.__setitem__(k, v) except StopIteration: pass diff --git a/tests/samples.bin b/tests/samples.bin index 3fcec96..e476315 100644 Binary files a/tests/samples.bin and b/tests/samples.bin differ diff --git a/tests/samples.txt b/tests/samples.txt index f44bc51..bdaee3a 100644 --- a/tests/samples.txt +++ b/tests/samples.txt @@ -36,6 +36,7 @@ dict2a: @"Missing close brace" dict3: @"Duplicate key" dict4: @"Unexpected close brace" + dict5: @"Missing value" double1: double2: float1: