fix(windows): preserve companion export tables

Guard PE32 export copies when the companion omits plaintext stub data. Reserve the complete export directory during compaction and validate file backing before overlaying it to prevent writes into the next section.

Add regression coverage for zero-filled export space, invalid directory ranges, and truncated source or destination sections.
This commit is contained in:
bfloat16 committed 2026-10-08 23:49:36 +08:00
1 parent 5bd1b0b07d
commit 6e233bbf18
3 files changed
+105 -12

No files matched your search

@@ -823,7 +823,15 @@ impl<'a> Unpacker<'a> {
let d = export_va as usize;
let s = export_file_off as usize;
let n = export_size as usize;
self.decompressed[d..d + n].copy_from_slice(&self.file_data[s..s + n]);
// Spliced companions may omit the stub's plaintext exports;
// the I/O adapter overlays those from the original stub later.
if s.checked_add(n)
.is_some_and(|end| end <= self.file_data.len())
&& d.checked_add(n)
.is_some_and(|end| end <= self.decompressed.len())
{
self.decompressed[d..d + n].copy_from_slice(&self.file_data[s..s + n]);
}
}
// ---- .text decrypt with decrypt_data8 (PE32 auto-detected formula) ----