]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pe-binary: fix "systemd-sbsign calculates wrong PE checksum"
authorhschloss <hauke.schlosser@pm.me>
Wed, 6 May 2026 15:07:40 +0000 (17:07 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 12 May 2026 12:15:05 +0000 (14:15 +0200)
src/shared/pe-binary.c

index b4b180d70133727fc4aef55a9037f174be62dfd4..2f7764c1393a8fc4c51cdf10155d65d51cf648a4 100644 (file)
@@ -487,7 +487,8 @@ int pe_checksum(int fd, uint32_t *ret) {
                         return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Short read from PE file");
 
                 for (size_t i = 0; i < (size_t) n / 2; i++) {
-                        if (off + i >= checksum_offset && off + i < checksum_offset + sizeof(pe_header->optional.CheckSum))
+                        size_t pos = off + i * sizeof(uint16_t);
+                        if (pos >= checksum_offset && pos < checksum_offset + sizeof(pe_header->optional.CheckSum))
                                 continue;
 
                         uint16_t val = le16toh(buf[i]);