Change file extraction to explicitly NUL-fill gaps

Instead of expecting pwrite to do it.
Fix reference counting bug in refactored file reassembly code.