sergio/takana
> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…
⎇ 5e8ff2348f48445c3c28eaddeca87c1e9e5305fb
recipes/0001-softmagic-compare-FILE_GUID-values-in-wire-format.patch
History
raw
Etapa G: tanda C tier-2 construye+corre — 6 al corpus (45->51) + wrap abuild local
1From 80297b6e252963d2c08f84f40bc3b5e517505ff4 Mon Sep 17 00:00:00 2001
2From: Natanael Copa <ncopa@alpinelinux.org>
3Date: Tue, 10 Mar 2026 11:54:48 +0100
4Subject: [PATCH] softmagic: compare FILE_GUID values in wire format
5
6Comparing GUIDs with memcmp() on native struct storage breaks on
7big-endian systems like s390x, since EFI GUIDs are stored in mixed-endian
8wire format. Convert the parsed magic GUID to on-disk byte order before
9comparing against file contents.
10
11Fixes efi-signature-list-sha256 test on s390x.
12---
13 src/file.h | 1 +
14 src/funcs.c | 20 ++++++++++++++++++++
15 src/softmagic.c | 2 +-
16 3 files changed, 22 insertions(+), 1 deletion(-)
17
18diff --git a/src/file.h b/src/file.h
19index 06cf91d1..6f4087cd 100644
20--- a/src/file.h
21+++ b/src/file.h
22@@ -559,6 +559,7 @@ file_protected int file_checkfmt(char *, size_t, const char *);
23 file_protected size_t file_printedlen(const struct magic_set *);
24 file_protected int file_print_guid(char *, size_t, const uint64_t *);
25 file_protected int file_parse_guid(const char *, uint64_t *);
26+file_protected int file_compare_guid(const uint64_t *, const uint64_t *);
27 file_protected int file_replace(struct magic_set *, const char *, const char *);
28 file_protected int file_printf(struct magic_set *, const char *, ...)
29 __attribute__((__format__(__printf__, 2, 3)));
30diff --git a/src/funcs.c b/src/funcs.c
31index fa62b26d..c3cc0341 100644
32--- a/src/funcs.c
33+++ b/src/funcs.c
34@@ -955,6 +955,26 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
35 #endif
36 }
37
38+file_protected int
39+file_compare_guid(const uint64_t *mguid, const uint64_t *fguid)
40+{
41+ const struct guid *m = CAST(const struct guid *, CAST(const void *, mguid));
42+ const unsigned char *f = CAST(const unsigned char *, CAST(const void *, fguid));
43+ unsigned char mbuf[16];
44+
45+ mbuf[0] = (unsigned char)(m->data1);
46+ mbuf[1] = (unsigned char)(m->data1 >> 8);
47+ mbuf[2] = (unsigned char)(m->data1 >> 16);
48+ mbuf[3] = (unsigned char)(m->data1 >> 24);
49+ mbuf[4] = (unsigned char)(m->data2);
50+ mbuf[5] = (unsigned char)(m->data2 >> 8);
51+ mbuf[6] = (unsigned char)(m->data3);
52+ mbuf[7] = (unsigned char)(m->data3 >> 8);
53+ memcpy(mbuf + 8, m->data4, 8);
54+
55+ return memcmp(mbuf, f, 16);
56+}
57+
58 file_protected int
59 file_pipe_closexec(int *fds)
60 {
61diff --git a/src/softmagic.c b/src/softmagic.c
62index 1a198005..ee85356d 100644
63--- a/src/softmagic.c
64+++ b/src/softmagic.c
65@@ -2407,7 +2407,7 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
66 return matched;
67 case FILE_GUID:
68 l = 0;
69- v = memcmp(m->value.guid, p->guid, sizeof(p->guid));
70+ v = file_compare_guid(m->value.guid, p->guid);
71 break;
72 default:
73 file_magerror(ms, "invalid type %d in magiccheck()", m->type);
74--
752.53.0
76