I would probably opt for Great Stuff (foam in a can), as long as the area has an open side the foam will expand in the direction of the opening. Allow it to set overnight. Then you can use a sharp serrated blade and rasp to form the foam when dry.
If you use a two part expanding foam that requires a chemistry degree to mix, then you might run into issues with expansion and warping things.
The S.