Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON.stringify() inherited array index bug #2324

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions releases/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,4 @@ duktape_releases:
- "Fix pointer overflow in String.prototype.startsWith/endsWith() with certain arguments (GH-2320)"
- "Fix assertion failure and incorrect behavior in some enumeration cases involving inherited duplicate keys (GH-2322)"
- "Fix unstable pointer in 'putvar' which could trigger e.g. in a with(proxy) statement (GH-2323)"
- "Fix unsafe behavior in JSON.stringify() when replacer argument is an array and Array.prototype has inherited index properties (GH-2202, GH-2324)"
2 changes: 1 addition & 1 deletion src-input/duk_bi_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,7 @@ void duk_bi_json_stringify_helper(duk_hthread *thr,
duk_uarridx_t plist_idx = 0;
duk_small_uint_t enum_flags;

js_ctx->idx_proplist = duk_push_array(thr); /* XXX: array internal? */
js_ctx->idx_proplist = duk_push_bare_array(thr);

enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY |
DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://github.com/svaarala/duktape/issues/2202

/*===
A
B
{}
done
===*/

print('A');
Object.defineProperty(Array.prototype, 0, { set: function () { } })
print('B');
print(String(JSON.stringify({ }, [ 0, 0])));
print('done');