diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2021-06-01 19:57:16 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2021-06-03 13:19:09 +0100 |
commit | 2a3129365d3bc0d4a41f107ef175920d1505d1f7 (patch) | |
tree | f65a1f3c2be4943dc6d1eeb4d36090a494bcf80f | |
parent | 25b8457be76ba09c2380e5058ca4878e1a7f5ee8 (diff) |
Bug 703902: Fix op stack management in sampled_data_continue()
Replace pop() (which does no checking, and doesn't handle stack extension
blocks) with ref_stack_pop() which does do all that.
We still use pop() in one case (it's faster), but we have to later use
ref_stack_pop() before calling sampled_data_sample() which also accesses the
op stack.
Fixes:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34675
-rw-r--r-- | psi/zfsample.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/psi/zfsample.c b/psi/zfsample.c index 0e8e4bc8d..00cd0cfdd 100644 --- a/psi/zfsample.c +++ b/psi/zfsample.c | |||
@@ -533,15 +533,19 @@ sampled_data_continue(i_ctx_t *i_ctx_p) | |||
533 | for (j = 0; j < bps; j++) | 533 | for (j = 0; j < bps; j++) |
534 | data_ptr[bps * i + j] = (byte)(cv >> ((bps - 1 - j) * 8)); /* MSB first */ | 534 | data_ptr[bps * i + j] = (byte)(cv >> ((bps - 1 - j) * 8)); /* MSB first */ |
535 | } | 535 | } |
536 | pop(num_out); /* Move op to base of result values */ | ||
537 | 536 | ||
538 | /* Check if we are done collecting data. */ | 537 | pop(num_out); /* Move op to base of result values */ |
539 | 538 | ||
539 | /* From here on, we have to use ref_stack_pop() rather than pop() | ||
540 | so that it handles stack extension blocks properly, before calling | ||
541 | sampled_data_sample() which also uses the op stack. | ||
542 | */ | ||
543 | /* Check if we are done collecting data. */ | ||
540 | if (increment_cube_indexes(params, penum->indexes)) { | 544 | if (increment_cube_indexes(params, penum->indexes)) { |
541 | if (stack_depth_adjust == 0) | 545 | if (stack_depth_adjust == 0) |
542 | pop(O_STACK_PAD); /* Remove spare stack space */ | 546 | ref_stack_pop(&o_stack, O_STACK_PAD); /* Remove spare stack space */ |
543 | else | 547 | else |
544 | pop(stack_depth_adjust - num_out); | 548 | ref_stack_pop(&o_stack, stack_depth_adjust - num_out); |
545 | /* Execute the closing procedure, if given */ | 549 | /* Execute the closing procedure, if given */ |
546 | code = 0; | 550 | code = 0; |
547 | if (esp_finish_proc != 0) | 551 | if (esp_finish_proc != 0) |
@@ -554,11 +558,11 @@ sampled_data_continue(i_ctx_t *i_ctx_p) | |||
554 | if ((O_STACK_PAD - stack_depth_adjust) < 0) { | 558 | if ((O_STACK_PAD - stack_depth_adjust) < 0) { |
555 | stack_depth_adjust = -(O_STACK_PAD - stack_depth_adjust); | 559 | stack_depth_adjust = -(O_STACK_PAD - stack_depth_adjust); |
556 | check_op(stack_depth_adjust); | 560 | check_op(stack_depth_adjust); |
557 | pop(stack_depth_adjust); | 561 | ref_stack_pop(&o_stack, stack_depth_adjust); |
558 | } | 562 | } |
559 | else { | 563 | else { |
560 | check_ostack(O_STACK_PAD - stack_depth_adjust); | 564 | check_ostack(O_STACK_PAD - stack_depth_adjust); |
561 | push(O_STACK_PAD - stack_depth_adjust); | 565 | ref_stack_push(&o_stack, O_STACK_PAD - stack_depth_adjust); |
562 | for (i=0;i<O_STACK_PAD - stack_depth_adjust;i++) | 566 | for (i=0;i<O_STACK_PAD - stack_depth_adjust;i++) |
563 | make_null(op - i); | 567 | make_null(op - i); |
564 | } | 568 | } |