From 9998182d92ad083d344c2b34d483925fda60c5ef Mon Sep 17 00:00:00 2001 From: "liuqiang.06" Date: Sat, 4 Jan 2025 00:59:13 +0800 Subject: [PATCH] fix: corrupted stack slot in _op_switch when case-sensitive --- decoder/decoder_native_test.go | 1 - internal/decoder/jitdec/assembler_regabi_amd64.go | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/decoder/decoder_native_test.go b/decoder/decoder_native_test.go index 45d326788..62e85b52a 100644 --- a/decoder/decoder_native_test.go +++ b/decoder/decoder_native_test.go @@ -81,7 +81,6 @@ func TestDecoder_OptionCaseSensitiveForManyKeys(t *testing.T) { var obj2 = TS{} d := NewDecoder(js) - // d.SetOptions(OptionCaseSensitive) err2 := d.Decode(&obj2) require.NoError(t, err2) require.Equal(t, obj, obj2) diff --git a/internal/decoder/jitdec/assembler_regabi_amd64.go b/internal/decoder/jitdec/assembler_regabi_amd64.go index 1ceb96b6c..29f6a4a84 100644 --- a/internal/decoder/jitdec/assembler_regabi_amd64.go +++ b/internal/decoder/jitdec/assembler_regabi_amd64.go @@ -1799,6 +1799,9 @@ func (self *_Assembler) _asm_OP_struct_field(p *_Instr) { self.Emit("TESTQ", _AX, _AX) // TESTQ AX, AX self.Sjmp("JNS" , "_end_{n}") // JNS _end_{n} self.Link("_unknown_{n}") + // HACK: because `_VAR_sr` maybe used in `F_vstring`, so we should clear here again for `_OP_switch`. + self.Emit("MOVQ" , jit.Imm(-1), _AX) // MOVQ $-1, AX + self.Emit("MOVQ" , _AX, _VAR_sr) // MOVQ AX, sr self.Emit("BTQ" , jit.Imm(_F_disable_unknown), _ARG_fv) // BTQ ${_F_disable_unknown}, fv self.Sjmp("JC" , _LB_field_error) // JC _field_error self.Link("_end_{n}") // _end_{n}: