Revert "Ensure all bytes consumed on decode (#2019)"

This reverts commit cd45787a91.
This commit is contained in:
Rafael Weinstein
2016-07-11 18:36:01 -07:00
parent cd45787a91
commit 48ab930ed2
4 changed files with 3 additions and 32 deletions
+2 -5
View File
@@ -35,12 +35,9 @@ setEncodeValue(encodeValue);
export function decodeValue(chunk: Chunk, vr: ValueReader): Value {
const data = chunk.data;
const br = new BinaryNomsReader(data);
const dec = new ValueDecoder(br, vr, staticTypeCache);
const dec = new ValueDecoder(new BinaryNomsReader(data), vr, staticTypeCache);
const v = dec.readValue();
if (br.pos() !== data.byteLength) {
throw new Error('Invalid chunk data: not all bytes consumed');
}
if (v instanceof ValueBase) {
setHash(v, chunk.hash);
}
-12
View File
@@ -10,7 +10,6 @@ import {assert} from 'chai';
import Blob from './blob.js';
import * as Bytes from './bytes.js';
import Chunk from './chunk.js';
import Hash from './hash.js';
import List, {newListLeafSequence} from './list.js';
import Map from './map.js';
@@ -388,17 +387,6 @@ suite('Encoding', () => {
newStruct('S', {x: 42, b: true}));
});
test('struct too much data', async () => {
const s = newStruct('S', {x: 42, b: true});
const c = encodeValue(s, null);
const data = c.data;
const buff = Bytes.alloc(data.byteLength + 1);
Bytes.copy(data, buff);
buff[data.byteLength] = 5; // Add a bogus extra byte
const c2 = new Chunk(buff);
assert.throws(() => decodeValue(c2, null));
});
test('struct with list', () => {
// struct S {l: List<String>}({l: ['a', 'b']})
assertEncoding([