| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- Subject: Handle parsing guids in big endian machines (Christoph Biedl)
- Origin: upstream, commit FILE5_47-93-g7a2b2a4b <https://github.com/file/file/commit/FILE5_47-93-g7a2b2a4b>
- Author: Christos Zoulas <christos@zoulas.com>
- Date: Sun May 17 17:10:25 2026 +0000
- --- a/src/compress.c
- +++ b/src/compress.c
- @@ -125,12 +125,11 @@
- static int
- zlibcmp(const unsigned char *buf)
- {
- - unsigned short x = 1;
- - unsigned char *s = CAST(unsigned char *, CAST(void *, &x));
- + unsigned short x;
-
- if ((buf[0] & 0xf) != 8 || (buf[0] & 0x80) != 0)
- return 0;
- - if (s[0] != 1) /* endianness test */
- + if (file_bigendian()) /* endianness test */
- x = buf[0] | (buf[1] << 8);
- else
- x = buf[1] | (buf[0] << 8);
- --- a/src/file.h
- +++ b/src/file.h
- @@ -596,6 +596,7 @@
- file_protected uintmax_t file_varint2uintmax_t(const unsigned char *, int,
- size_t *);
-
- +file_protected int file_bigendian(void);
- file_protected void file_badread(struct magic_set *);
- file_protected void file_badseek(struct magic_set *);
- file_protected void file_oomem(struct magic_set *, size_t);
- --- a/src/funcs.c
- +++ b/src/funcs.c
- @@ -52,6 +52,18 @@
- #define SIZE_MAX ((size_t)~0)
- #endif
-
- +file_protected int
- +file_bigendian(void)
- +{
- + union {
- + unsigned short x;
- + unsigned char s[sizeof(unsigned short)];
- + } u;
- +
- + u.x = 1;
- + return u.s[0] != 1;
- +}
- +
- file_protected char *
- file_copystr(char *buf, size_t blen, size_t width, const char *str)
- {
- @@ -932,6 +944,13 @@
- !getxvalue(&g->data4[6], s + 8, 2) ||
- !getxvalue(&g->data4[7], s + 10, 2))
- return -1;
- +
- + if (file_bigendian()) {
- + g->data1 = file_swap4(g->data1);
- + g->data2 = file_swap2(g->data2);
- + g->data3 = file_swap2(g->data3);
- +
- + }
- return 0;
- }
-
|