Skip to content

Commit

Permalink
Merge pull request #2318 from svaarala/cbor-encode-assert-gh2316
Browse files Browse the repository at this point in the history
Fix CBOR.encode() assertion failure
  • Loading branch information
svaarala authored Jun 11, 2020
2 parents 0e4d504 + 430d9f2 commit 51e49c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions releases/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1363,3 +1363,4 @@ duktape_releases:
- "Fix duk_suspend() handling of finalizers, if main thread was suspended finalizers triggered by other threads could consistenly fail (GH-2282)"
- "Improve DUK_USE_OS_STRING for macOS, iOS, watchOS, and tvOS (GH-2288)"
- "Fix nested error handling bug for out-of-memory during error creation (GH-2278, GH-2290)"
- "Fix failing assert for CBOR.encode() when argument is a zero-size dynamic plain array (GH-2316, GH-2318)"
8 changes: 3 additions & 5 deletions src-input/duk_bi_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tests/ecmascript/test-bug-assert-cbor-encode-gh2316.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 51e49c7

Please sign in to comment.