cherry-pick.FILE5_30-46-g1fa18af6.check-read-bounds-for-vector-before-reading.patch 899 B

12345678910111213141516171819202122232425262728
  1. Subject: Check read bounds for vector before reading. Found by oss-fuzz
  2. Origin: FILE5_30-46-g1fa18af6
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Apr 12 14:57:22 2017 +0000
  5. --- a/src/cdf.c
  6. +++ b/src/cdf.c
  7. @@ -959,7 +959,12 @@
  8. inp[i].pi_type = CDF_GETUINT32(q, 0);
  9. DPRINTF(("%" SIZE_T_FORMAT "u) id=%x type=%x offs=0x%tx,0x%x\n",
  10. i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
  11. + left = CAST(size_t, e - q);
  12. if (inp[i].pi_type & CDF_VECTOR) {
  13. + if (left < sizeof(uint32_t)) {
  14. + DPRINTF(("missing CDF_VECTOR length\n"));
  15. + goto out;
  16. + }
  17. nelements = CDF_GETUINT32(q, 1);
  18. if (nelements == 0) {
  19. DPRINTF(("CDF_VECTOR with nelements == 0\n"));
  20. @@ -970,7 +975,6 @@
  21. nelements = 1;
  22. slen = 1;
  23. }
  24. - left = CAST(size_t, e - q);
  25. o4 = slen * sizeof(uint32_t);
  26. if (inp[i].pi_type & (CDF_ARRAY|CDF_BYREF|CDF_RESERVED))
  27. goto unknown;