cherry-pick.FILE5_34-13-gcd752e7c.try-to-use-the-right-off-t-max.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Subject: Try to use the "right" off_t_max
  2. Origin: FILE5_34-13-gcd752e7c <https://github.com/file/file/commit/FILE5_34-13-gcd752e7c>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Aug 1 09:53:18 2018 +0000
  5. --- a/src/apprentice.c
  6. +++ b/src/apprentice.c
  7. @@ -55,11 +55,6 @@
  8. #include <limits.h>
  9. #endif
  10. -#ifndef SSIZE_MAX
  11. -#define MAXMAGIC_SIZE ((ssize_t)0x7fffffff)
  12. -#else
  13. -#define MAXMAGIC_SIZE SSIZE_MAX
  14. -#endif
  15. #define EATAB {while (isascii((unsigned char) *l) && \
  16. isspace((unsigned char) *l)) ++l;}
  17. @@ -300,6 +295,15 @@
  18. return p->type;
  19. }
  20. +private off_t
  21. +maxoff_t(void) {
  22. + if (sizeof(off_t) == sizeof(int))
  23. + return CAST(off_t, INT_MAX);
  24. + if (sizeof(off_t) == sizeof(long))
  25. + return CAST(off_t, LONG_MAX);
  26. + return 0x7fffffff;
  27. +}
  28. +
  29. private int
  30. get_standard_integer_type(const char *l, const char **t)
  31. {
  32. @@ -2950,7 +2954,7 @@
  33. file_error(ms, errno, "cannot stat `%s'", dbname);
  34. goto error;
  35. }
  36. - if (st.st_size < 8 || st.st_size > MAXMAGIC_SIZE) {
  37. + if (st.st_size < 8 || st.st_size > maxoff_t()) {
  38. file_error(ms, 0, "file `%s' is too %s", dbname,
  39. st.st_size < 8 ? "small" : "large");
  40. goto error;