From bd183a4069080e303852b0255f4361e9ebc20b8e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 30 Oct 2023 12:57:31 +0300 Subject: [PATCH] Fixed codegeneration for MATCH Fixes oss-fuzz #63681 --- ext/opcache/jit/zend_jit_ir.c | 10 ++++++++++ ext/opcache/tests/jit/match_002.phpt | 21 +++++++++++++++++++++ ext/opcache/tests/jit/match_003.phpt | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 ext/opcache/tests/jit/match_002.phpt create mode 100644 ext/opcache/tests/jit/match_003.phpt diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c index 508ab81ba73..4a48140a581 100644 --- a/ext/opcache/jit/zend_jit_ir.c +++ b/ext/opcache/jit/zend_jit_ir.c @@ -15572,6 +15572,16 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_ } ZEND_HASH_FOREACH_END(); _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ref); } + } else if (!(op1_info & MAY_BE_UNDEF)) { + if (next_opline) { + if (next_opline == default_opline) { + ir_END_list(continue_list); + } else { + jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); + } + } else { + _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ir_END()); + } } if (op1_info & MAY_BE_UNDEF) { diff --git a/ext/opcache/tests/jit/match_002.phpt b/ext/opcache/tests/jit/match_002.phpt new file mode 100644 index 00000000000..a0940ad69e2 --- /dev/null +++ b/ext/opcache/tests/jit/match_002.phpt @@ -0,0 +1,21 @@ +--TEST-- +JIT Match: 002 impossible input +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +--FILE-- +0, + default=>42 + }; +}; +var_dump(foo(new C)); +?> +--EXPECT-- +int(42) diff --git a/ext/opcache/tests/jit/match_003.phpt b/ext/opcache/tests/jit/match_003.phpt new file mode 100644 index 00000000000..02c591a63f4 --- /dev/null +++ b/ext/opcache/tests/jit/match_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +JIT Match: 003 impossible input +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +--FILE-- +0 + }; +}; +?> +DONE +--EXPECT-- +DONE