From 1d16af91d0eba3eae61519ee0bf75c23a83d6c15 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 27 Apr 2023 09:55:04 +1000 Subject: [PATCH 1/4] Switch on the removed opcodes for 3.12+ --- src/native/codetable_gen.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/codetable_gen.cc b/src/native/codetable_gen.cc index 088910c2..d706adac 100644 --- a/src/native/codetable_gen.cc +++ b/src/native/codetable_gen.cc @@ -42,8 +42,10 @@ static bool dummy_initializer = []() { opcode_caches[COMPARE_OP] = 2; opcode_caches[LOAD_GLOBAL] = 5; opcode_caches[BINARY_OP] = 1; +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION == 11 opcode_caches[LOAD_METHOD] = 10; opcode_caches[PRECALL] = 1; +#endif opcode_caches[CALL] = 4; return true; }(); From acb3755709a424a7255a8eeb72e84736f2282e3a Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 27 Apr 2023 09:59:45 +1000 Subject: [PATCH 2/4] Update version filter --- src/version_dependent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version_dependent.py b/src/version_dependent.py index 62dfcba6..43864f97 100644 --- a/src/version_dependent.py +++ b/src/version_dependent.py @@ -37,10 +37,10 @@ PYTHON_VERSION = sys.version_info[:2] -if PYTHON_VERSION < (3, 6) or PYTHON_VERSION > (3, 11): +if PYTHON_VERSION < (3, 6) or PYTHON_VERSION > (3, 12): raise RuntimeError( "You are fuzzing on an unsupported python version: " - + f"{PYTHON_VERSION[0]}.{PYTHON_VERSION[1]}. Only 3.6 - 3.11 are " + + f"{PYTHON_VERSION[0]}.{PYTHON_VERSION[1]}. Only 3.6 - 3.12 are " + "supported by atheris 2.0. Use atheris 1.0 for older python versions." ) From 2f78f43205ceb6fa31b404c60b88538be80b578f Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 27 Apr 2023 10:01:27 +1000 Subject: [PATCH 3/4] Don't use JUMP_IF_TRUE_OR_POP or JUMP_IF_FALSE_OR_POP in 3.12+ --- src/version_dependent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version_dependent.py b/src/version_dependent.py index 43864f97..a763e1bc 100644 --- a/src/version_dependent.py +++ b/src/version_dependent.py @@ -139,7 +139,7 @@ "JUMP_IF_TRUE_OR_POP", "JUMP_IF_FALSE_OR_POP", ]) -else: +elif PYTHON_VERSION < (3, 12): HAVE_REL_REFERENCE.extend([ "JUMP_IF_TRUE_OR_POP", "JUMP_IF_FALSE_OR_POP", From cd5c6a9e723af15490a817183de046ccdd08bbd9 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 27 Apr 2023 10:34:42 +1000 Subject: [PATCH 4/4] Update version deps. There is no PRECALL anymore --- src/version_dependent.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/version_dependent.py b/src/version_dependent.py index a763e1bc..784c5b3e 100644 --- a/src/version_dependent.py +++ b/src/version_dependent.py @@ -14,7 +14,7 @@ # limitations under the License. """This module manages the version specific aspects of bytecode instrumentation. -Accross Python versions there are variations in: +Across Python versions there are variations in: - Instructions - Instruction arguments - Shape of a code object @@ -328,7 +328,7 @@ def get_lnotab(code, listing): return bytes(lnotab) -if (3, 11) <= PYTHON_VERSION <= (3, 11): +if (3, 11) <= PYTHON_VERSION: from .native import _generate_codetable def get_lnotab(code, listing): ret = _generate_codetable(code, listing) @@ -391,7 +391,7 @@ def parse_exceptiontable(code): return ExceptionTable([]) -if (3, 11) <= PYTHON_VERSION <= (3, 11): +if (3, 11) <= PYTHON_VERSION: from .native import _generate_exceptiontable def generate_exceptiontable(original_code, exception_table_entries): @@ -520,7 +520,8 @@ def args_terminator(): # 3.11 requires a PRECALL instruction prior to every CALL instruction. def call(argc: int): ret = [] - ret.append((dis.opmap["PRECALL"], argc)) + if PYTHON_VERSION == (3, 11): + ret.append((dis.opmap["PRECALL"], argc)) ret.append((dis.opmap["CALL"], argc)) return ret @@ -528,6 +529,7 @@ def call(argc: int): # itself, and a null terminator. CALLABLE_STACK_ENTRIES = 2 + ### disassembler compatibility ### # In 3.11, we need to pass show_caches=True.