Foxit Reader FileAttachment annotation use-after-free vulnerability

We discussed this vulnerability during Episode 76 on 11 May 2021

Fairly simple to understand bug in the JS Engine (v8) used by Foxit Reader. The crash is just two lines of code.

this.pageNum = 1;
this.addAnnot({page: 1, type: "FileAttachment", point: [11,14,6,8]});

What happens here is the pageNum is changed, this queues the close handler of page0 to be executed. Then the FileAttachment annotation is created, this triggers a file picker dialog to be shown. This dialog blocks execution of the main thread until it returns.

While execution is blocked, page0 elsewhere is closing and attempts to get annotations objects and destroy them. This results in the annotations backing object getting freed from under the dialog. Once the dialog is dismissed the rest of the code executes on the freed object.