From 837645e31166e141149cc7a984ab832ac73d4896 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Tue, 10 Sep 2024 16:53:29 -0700 Subject: [PATCH] Fix data race in _PyInstruction_GetLength Read the opcode atomically, the interpreter may be specializing it --- Python/instrumentation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 9a7cc027553f4f..18b77193fc4c52 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -327,7 +327,8 @@ _PyInstruction_GetLength(PyCodeObject *code, int offset) { ASSERT_WORLD_STOPPED_OR_LOCKED(code); - int opcode = _PyCode_CODE(code)[offset].op.code; + int opcode = + FT_ATOMIC_LOAD_UINT8_RELAXED(_PyCode_CODE(code)[offset].op.code); assert(opcode != 0); assert(opcode != RESERVED); if (opcode == INSTRUMENTED_LINE) {