diff --git a/src/core/u-bincode.c b/src/core/u-bincode.c index f7d2600959..39f77edda3 100644 --- a/src/core/u-bincode.c +++ b/src/core/u-bincode.c @@ -1292,7 +1292,7 @@ static REBCNT EncodedVINT_Size(REBU64 value) { case SYM_UB: next = ++value; if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (!IS_INTEGER(next)) goto error_next_value; i = 0; // could be optimized? nbits = VAL_INT32(next); @@ -1317,7 +1317,7 @@ static REBCNT EncodedVINT_Size(REBU64 value) { case SYM_FB: next = ++value; if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (!IS_INTEGER(next)) goto error_next_value; u = 0; // could be optimized? nbits = VAL_INT32(next); @@ -1498,7 +1498,7 @@ static REBCNT EncodedVINT_Size(REBU64 value) { // uses absolute positioning from series HEAD! next = ++value; if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (!IS_INTEGER(next)) goto error_next_value; i = VAL_INT32(next) - (cmd == SYM_AT ? 1 : 0); ASSERT_INDEX_RANGE(buffer_read, i, value); VAL_INDEX(buffer_read) = i; @@ -1512,8 +1512,9 @@ static REBCNT EncodedVINT_Size(REBU64 value) { break; case SYM_SKIP: next = ++value; - if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (IS_GET_WORD(next)) + next = Get_Var(next); + if (!IS_INTEGER(next)) goto error_next_value; i = VAL_INDEX(buffer_read) + VAL_INT32(next); ASSERT_INDEX_RANGE(buffer_read, i, value); VAL_INDEX(buffer_read) = i; //TODO: range test @@ -1522,7 +1523,7 @@ static REBCNT EncodedVINT_Size(REBU64 value) { case SYM_PAD: next = ++value; if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (!IS_INTEGER(next)) goto error_next_value; i = VAL_INDEX(buffer_read) % VAL_INT32(next); if (i > 0) { i = VAL_INT32(next) - i; @@ -1534,7 +1535,7 @@ static REBCNT EncodedVINT_Size(REBU64 value) { case SYM_SKIPBITS: next = ++value; if (IS_GET_WORD(next)) next = Get_Var(next); - if (!IS_INTEGER(next)) Trap1(RE_INVALID_SPEC, value); + if (!IS_INTEGER(next)) goto error_next_value; i = VAL_INT32(next); if (i >= 8) { i /= 8; @@ -1760,5 +1761,8 @@ static REBCNT EncodedVINT_Size(REBU64 value) { error: Trap_Word(RE_DIALECT, SYM_BINCODE, value); +error_next_value: + if (IS_END(next)) value--; + Trap1(RE_INVALID_SPEC, value); } #endif //IGNORE_BINCODE diff --git a/src/tests/units/bincode-test.r3 b/src/tests/units/bincode-test.r3 index 876f36497c..dac7430153 100644 --- a/src/tests/units/bincode-test.r3 +++ b/src/tests/units/bincode-test.r3 @@ -529,5 +529,21 @@ is-protected-error?: func[code][ empty? head b/buffer empty? head b/buffer-write ] +===end-group=== + + +===start-group=== "BinCode other issues" + --test-- "Missing additional read value" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2601 + --assert all [error? e: try [binary/read #{010203} [UI8 UB]] e/arg1 = 'UB] + --assert all [error? e: try [binary/read #{010203} [UI8 FB]] e/arg1 = 'FB] + --assert all [error? e: try [binary/read #{010203} [UI8 SB]] e/arg1 = 'SB] + --assert all [error? e: try [binary/read #{010203} [UI8 AT]] e/arg1 = 'AT] + --assert all [error? e: try [binary/read #{010203} [UI8 ATz]] e/arg1 = 'ATz] + --assert all [error? e: try [binary/read #{010203} [UI8 PAD]] e/arg1 = 'PAD] + --assert all [error? e: try [binary/read #{010203} [UI8 SKIP]] e/arg1 = 'SKIP] + --assert all [error? e: try [binary/read #{010203} [UI8 SKIPBITS]] e/arg1 = 'SKIPBITS] + +===end-group=== ~~~end-file~~~ \ No newline at end of file