Skip to content
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
4 changes: 3 additions & 1 deletion bplistParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ export function parseBuffer<T = any>(buffer: Buffer): [T] {
if (debug) {
console.log(" DICT #" + tableOffset + ": Mapped " + key + " to " + val);
}
dict[key] = val;
// not `dict[key] = val`: for "__proto__" (or a key that coerces to
// it) that calls the prototype setter instead of adding the key
Object.defineProperty(dict, key, { value: val, enumerable: true, writable: true, configurable: true });
}
return dict;
}
Expand Down
19 changes: 19 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ describe('bplist-parser', function () {
assert.deepStrictEqual(values, cases.map(({expected}) => expected));
});

it('keeps a "__proto__" dictionary key as an own property', function () {
// plistlib.dumps({"__proto__": {"isAdmin": True}, "name": "x"}, fmt=plistlib.FMT_BINARY)
const buf = Buffer.from(
'YnBsaXN0MDDSAQIDBllfX3Byb3RvX19UbmFtZdEEBVdpc0FkbWluCVF4CA0XHB8nKAAAAAAAAAEBAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAq',
'base64'
);
const [dict] = bplist.parseBuffer(buf);
assert.deepStrictEqual(Object.keys(dict), ['__proto__', 'name']);
assert.equal(Object.getPrototypeOf(dict), Object.prototype);
assert.equal(dict.isAdmin, undefined);
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(dict, '__proto__'), {
value: { isAdmin: true },
enumerable: true,
writable: true,
configurable: true
});
assert.equal(dict.name, 'x');
});

it('rejects a truncated plist header', function () {
assert.throws(function () {
bplist.parseBuffer(Buffer.from('bplist00'));
Expand Down
Loading