app.doScript causing memory corruption for download

Fetch + app.doScript bug

InDesign / UXP

High Level Description

We have a plugin with the following behavior:

  1.    On an interval, run an app.doScript
    
  2.    Fetch a file.
    

These behaviors together create some sort of time related bug. For large enough files (On my machine that means ~1MB), some of the binary data in that file will be rearranged, causing it to be corrupted or damaged.

Justification

If we could move away from app.doScript completely, we would. We need app.doScript primarily for the following reasons:

  1.    The ability to undo.
    
  2.    XMP support in InDesign.
    
  3.    The ability to support scripts that work on both InDesign server and InDesign desktop (UXP scripts are not where they need to be to make the switch).
    
  4.    The ability to communicate with / open and run other Adobe applications.
    

Example

I’ve attached a zip with a minimal example plugin.

The plugin fetches files, hashes their contents, then outputs the hash. It does this multiple times for two different file sizes. On my Mac, the smaller file size works fine, but the larger file size will display different hashes (due to the binary data being rearranged). On my Windows machine, both fail.

If you comment out the last line (the setInterval), both file sizes work on Mac and Windows.

FetchDoScriptBug.zip (7.5 KB)

I’ll also add, I’ve had app.doScript lead to complete plugin failure. It ended up in a state where I could click on certain UI elements but other ones were completely unresponsive. I really have no idea what internally got messed up

Seems that app.doScript struggles with asynchronous operations. I have an issue with that too, when using the file system (see my Problem with Undo and File)