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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. --- a/src/compress.c
  6. +++ b/src/compress.c
  7. @@ -125,12 +125,11 @@
  8. static int
  9. zlibcmp(const unsigned char *buf)
  10. {
  11. - unsigned short x = 1;
  12. - unsigned char *s = CAST(unsigned char *, CAST(void *, &x));
  13. + unsigned short x;
  14. if ((buf[0] & 0xf) != 8 || (buf[0] & 0x80) != 0)
  15. return 0;
  16. - if (s[0] != 1) /* endianness test */
  17. + if (file_bigendian()) /* endianness test */
  18. x = buf[0] | (buf[1] << 8);
  19. else
  20. x = buf[1] | (buf[0] << 8);
  21. --- a/src/file.h
  22. +++ b/src/file.h
  23. @@ -596,6 +596,7 @@
  24. file_protected uintmax_t file_varint2uintmax_t(const unsigned char *, int,
  25. size_t *);
  26. +file_protected int file_bigendian(void);
  27. file_protected void file_badread(struct magic_set *);
  28. file_protected void file_badseek(struct magic_set *);
  29. file_protected void file_oomem(struct magic_set *, size_t);
  30. --- a/src/funcs.c
  31. +++ b/src/funcs.c
  32. @@ -52,6 +52,18 @@
  33. #define SIZE_MAX ((size_t)~0)
  34. #endif
  35. +file_protected int
  36. +file_bigendian(void)
  37. +{
  38. + union {
  39. + unsigned short x;
  40. + unsigned char s[sizeof(unsigned short)];
  41. + } u;
  42. +
  43. + u.x = 1;
  44. + return u.s[0] != 1;
  45. +}
  46. +
  47. file_protected char *
  48. file_copystr(char *buf, size_t blen, size_t width, const char *str)
  49. {
  50. @@ -932,6 +944,13 @@
  51. !getxvalue(&g->data4[6], s + 8, 2) ||
  52. !getxvalue(&g->data4[7], s + 10, 2))
  53. return -1;
  54. +
  55. + if (file_bigendian()) {
  56. + g->data1 = file_swap4(g->data1);
  57. + g->data2 = file_swap2(g->data2);
  58. + g->data3 = file_swap2(g->data3);
  59. +
  60. + }
  61. return 0;
  62. }