1664724087.FILE5_43-55-gbd3cac67.handle-negative-numbers-in-overflow-calculation.patch 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Subject: Handle negative numbers in overflow calculation
  2. Origin: FILE5_43-55-gbd3cac67 <https://github.com/file/file/commit/FILE5_43-55-gbd3cac67>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Sun Oct 2 15:21:27 2022 +0000
  5. --- a/src/apprentice.c
  6. +++ b/src/apprentice.c
  7. @@ -2832,6 +2832,7 @@
  8. {
  9. char *ep;
  10. uint64_t ull;
  11. + int y;
  12. switch (m->type) {
  13. case FILE_BESTRING16:
  14. @@ -2916,21 +2917,25 @@
  15. switch (ts) {
  16. case 1:
  17. x = CAST(uint64_t, ull & ~0xffULL);
  18. + y = (x & ~0xffULL) != ~0xffULL;
  19. break;
  20. case 2:
  21. x = CAST(uint64_t, ull & ~0xffffULL);
  22. + y = (x & ~0xffffULL) != ~0xffffULL;
  23. break;
  24. case 4:
  25. x = CAST(uint64_t, ull & ~0xffffffffULL);
  26. + y = (x & ~0xffffffffULL) != ~0xffffffffULL;
  27. break;
  28. case 8:
  29. x = 0;
  30. + y = 0;
  31. break;
  32. default:
  33. fprintf(stderr, "Bad width %zu", ts);
  34. abort();
  35. }
  36. - if (x) {
  37. + if (x && y) {
  38. file_magwarn(ms, "Overflow for numeric"
  39. " type `%s' value %#" PRIx64,
  40. type_tbl[m->type].name, ull);