A first mitigation to prevent crash and just return an empty output file could be to initialize each section size to zero. Other options to explore is to have each section update the size as soon as anything is written (requiring an additional write for each write to a section).
If an application exits due to an assert (or otherwise unexpected exit). The size fields for each section remains at it's allocated size. Under normal circumstances, that size is updated when the application exits.
A first mitigation to prevent crash and just return an empty output file could be to initialize each section size to zero. Other options to explore is to have each section update the size as soon as anything is written (requiring an additional write for each write to a section).