Browse Source

Fix CBOR.encode() assertion failure

v2.6-maintenance
Sami Vaarala 4 years ago
parent
commit
5a5bdad678
  1. 8
      src-input/duk_bi_cbor.c
  2. 13
      tests/ecmascript/test-bug-assert-cbor-encode-gh2316.js

8
src-input/duk_bi_cbor.c

@ -487,7 +487,7 @@ DUK_LOCAL void duk__cbor_encode_object(duk_cbor_encode_context *enc_ctx) {
duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U);
duk__cbor_encode_ensure(enc_ctx, len);
p = enc_ctx->ptr;
duk_memcpy((void *) p, (const void *) buf, len);
duk_memcpy_unsafe((void *) p, (const void *) buf, len);
p += len;
enc_ctx->ptr = p;
} else {
@ -542,7 +542,7 @@ DUK_LOCAL void duk__cbor_encode_buffer(duk_cbor_encode_context *enc_ctx) {
duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U);
duk__cbor_encode_ensure(enc_ctx, len);
p = enc_ctx->ptr;
duk_memcpy((void *) p, (const void *) buf, len);
duk_memcpy_unsafe((void *) p, (const void *) buf, len);
p += len;
enc_ctx->ptr = p;
}
@ -945,9 +945,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, d
buf_data = (duk_uint8_t *) duk_require_buffer(dec_ctx->thr, idx, &buf_size);
if (p != NULL) {
if (buf_size > 0U) {
duk_memcpy((void *) p, (const void *) buf_data, buf_size);
}
duk_memcpy_unsafe((void *) p, (const void *) buf_data, buf_size);
p += buf_size;
} else {
total_size += buf_size;

13
tests/ecmascript/test-bug-assert-cbor-encode-gh2316.js

@ -0,0 +1,13 @@
// https://github.com/svaarala/duktape/issues/2316
/*===
done
===*/
function main() {
var v0 = [];
var v4 = Duktape.dec("base64",v0);
var v5 = CBOR.encode(v4);
}
main();
print('done');
Loading…
Cancel
Save