fix: crash in MessagePortMain
with some postMessage
params (#37585)
* fix: crash in MessagePortMain postMessage * Update shell/browser/api/message_port.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
1e106c8aa4
commit
b27e4cae21
2 changed files with 65 additions and 6 deletions
|
@ -355,6 +355,31 @@ describe('ipc module', () => {
|
|||
expect(port2).not.to.be.null();
|
||||
});
|
||||
|
||||
it('throws an error when an invalid parameter is sent to postMessage', () => {
|
||||
const { port1 } = new MessageChannelMain();
|
||||
|
||||
expect(() => {
|
||||
const buffer = new ArrayBuffer(10) as any;
|
||||
port1.postMessage(null, [buffer]);
|
||||
}).to.throw(/Port at index 0 is not a valid port/);
|
||||
|
||||
expect(() => {
|
||||
port1.postMessage(null, ['1' as any]);
|
||||
}).to.throw(/Port at index 0 is not a valid port/);
|
||||
|
||||
expect(() => {
|
||||
port1.postMessage(null, [new Date() as any]);
|
||||
}).to.throw(/Port at index 0 is not a valid port/);
|
||||
});
|
||||
|
||||
it('throws when postMessage transferables contains the source port', () => {
|
||||
const { port1 } = new MessageChannelMain();
|
||||
|
||||
expect(() => {
|
||||
port1.postMessage(null, [port1]);
|
||||
}).to.throw(/Port at index 0 contains the source port./);
|
||||
});
|
||||
|
||||
it('can send messages within the process', async () => {
|
||||
const { port1, port2 } = new MessageChannelMain();
|
||||
port2.postMessage('hello');
|
||||
|
@ -423,7 +448,7 @@ describe('ipc module', () => {
|
|||
const { port1 } = new MessageChannelMain();
|
||||
expect(() => {
|
||||
port1.postMessage(null, [null] as any);
|
||||
}).to.throw(/conversion failure/);
|
||||
}).to.throw(/Port at index 0 is not a valid port/);
|
||||
});
|
||||
|
||||
it('throws when passing duplicate ports', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue