Skip to content

Commit

Permalink
FIX: leak of internal #(end) value in bincode error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jun 12, 2024
1 parent 3cb158b commit d8e1af2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/core/u-bincode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/tests/units/bincode-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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~~~

0 comments on commit d8e1af2

Please sign in to comment.