2
1

0003-oss-fuzz-30715-Check-stack-limits-after-function-evaluation.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 7861fcad13c497728189feafb41cd57b5b50ea25 Mon Sep 17 00:00:00 2001
  2. From: Chris Liddell <chris.liddell@artifex.com>
  3. Date: Fri, 12 Feb 2021 10:34:23 +0000
  4. Subject: [PATCH] oss-fuzz 30715: Check stack limits after function evaluation.
  5. During function result sampling, after the callout to the Postscript
  6. interpreter, make sure there is enough stack space available before pushing
  7. or popping entries.
  8. In thise case, the Postscript procedure for the "function" is totally invalid
  9. (as a function), and leaves the op stack in an unrecoverable state (as far as
  10. function evaluation is concerned). We end up popping more entries off the
  11. stack than are available.
  12. To cope, add in stack limit checking to throw an appropriate error when this
  13. happens.
  14. [Retrieved from:
  15. https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=7861fcad13c497728189feafb41cd57b5b50ea25]
  16. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  17. ---
  18. psi/zfsample.c | 14 +++++++++++---
  19. 1 file changed, 11 insertions(+), 3 deletions(-)
  20. diff --git a/psi/zfsample.c b/psi/zfsample.c
  21. index 290809405..652ae02c6 100644
  22. --- a/psi/zfsample.c
  23. +++ b/psi/zfsample.c
  24. @@ -551,9 +551,17 @@ sampled_data_continue(i_ctx_t *i_ctx_p)
  25. } else {
  26. if (stack_depth_adjust) {
  27. stack_depth_adjust -= num_out;
  28. - push(O_STACK_PAD - stack_depth_adjust);
  29. - for (i=0;i<O_STACK_PAD - stack_depth_adjust;i++)
  30. - make_null(op - i);
  31. + if ((O_STACK_PAD - stack_depth_adjust) < 0) {
  32. + stack_depth_adjust = -(O_STACK_PAD - stack_depth_adjust);
  33. + check_op(stack_depth_adjust);
  34. + pop(stack_depth_adjust);
  35. + }
  36. + else {
  37. + check_ostack(O_STACK_PAD - stack_depth_adjust);
  38. + push(O_STACK_PAD - stack_depth_adjust);
  39. + for (i=0;i<O_STACK_PAD - stack_depth_adjust;i++)
  40. + make_null(op - i);
  41. + }
  42. }
  43. }
  44. --
  45. 2.25.1