FILE5_47-93-g7a2b2a4b.handle-parsing-guids-in-big-endian-machines.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Subject: Handle parsing guids in big endian machines (Christoph Biedl)
  2. Origin: upstream, commit FILE5_47-93-g7a2b2a4b <https://github.com/file/file/commit/FILE5_47-93-g7a2b2a4b>
  3. Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Sun May 17 17:10:25 2026 +0000
  5. Forwarded: not-needed
  6. --- a/src/compress.c
  7. +++ b/src/compress.c
  8. @@ -125,12 +125,11 @@
  9. static int
  10. zlibcmp(const unsigned char *buf)
  11. {
  12. - unsigned short x = 1;
  13. - unsigned char *s = CAST(unsigned char *, CAST(void *, &x));
  14. + unsigned short x;
  15. if ((buf[0] & 0xf) != 8 || (buf[0] & 0x80) != 0)
  16. return 0;
  17. - if (s[0] != 1) /* endianness test */
  18. + if (file_bigendian()) /* endianness test */
  19. x = buf[0] | (buf[1] << 8);
  20. else
  21. x = buf[1] | (buf[0] << 8);
  22. --- a/src/file.h
  23. +++ b/src/file.h
  24. @@ -596,6 +596,7 @@
  25. file_protected uintmax_t file_varint2uintmax_t(const unsigned char *, int,
  26. size_t *);
  27. +file_protected int file_bigendian(void);
  28. file_protected void file_badread(struct magic_set *);
  29. file_protected void file_badseek(struct magic_set *);
  30. file_protected void file_oomem(struct magic_set *, size_t);
  31. --- a/src/funcs.c
  32. +++ b/src/funcs.c
  33. @@ -52,6 +52,18 @@
  34. #define SIZE_MAX ((size_t)~0)
  35. #endif
  36. +file_protected int
  37. +file_bigendian(void)
  38. +{
  39. + union {
  40. + unsigned short x;
  41. + unsigned char s[sizeof(unsigned short)];
  42. + } u;
  43. +
  44. + u.x = 1;
  45. + return u.s[0] != 1;
  46. +}
  47. +
  48. file_protected char *
  49. file_copystr(char *buf, size_t blen, size_t width, const char *str)
  50. {
  51. @@ -932,6 +944,13 @@
  52. !getxvalue(&g->data4[6], s + 8, 2) ||
  53. !getxvalue(&g->data4[7], s + 10, 2))
  54. return -1;
  55. +
  56. + if (file_bigendian()) {
  57. + g->data1 = file_swap4(g->data1);
  58. + g->data2 = file_swap2(g->data2);
  59. + g->data3 = file_swap2(g->data3);
  60. +
  61. + }
  62. return 0;
  63. }