:: commit b7bf7f12f5dca023320bbc63033f208bb74b550b

Kamila Szewczyk <k@iczelia.net> — 2026-05-01 13:35

parents: 1cb8b4a8bb

lib/pe: reject SectionAlignment = 0

Prevents potential division-by-zero crashes. Found by fuzzing.
diff --git a/common/lib/pe.c b/common/lib/pe.c
index d1e6a58e..fb711bd5 100644
--- a/common/lib/pe.c
+++ b/common/lib/pe.c
@@ -275,6 +275,10 @@ bool pe64_load(uint8_t *image, size_t file_size, uint64_t *entry_point, uint64_t
     uint64_t image_size = nt_hdrs->OptionalHeader.SizeOfImage;
     uint64_t alignment = nt_hdrs->OptionalHeader.SectionAlignment;
 
+    if (alignment == 0) {
+        panic(true, "pe: SectionAlignment is zero");
+    }
+
     if (alignment > 1 && (alignment & (alignment - 1)) != 0) {
         panic(true, "pe: SectionAlignment is not a power of 2");
     }
tab: 248 wrap: offon