From 073545ce30358a62064053d3bf0d945591d63d18 Mon Sep 17 00:00:00 2001 From: Kevin Langman Date: Wed, 15 Jan 2025 17:01:58 -0500 Subject: [PATCH] Sign extend 32bit offsets in inlineIntrinsicInflate Without sign extending the 32bit offsets, it is possible for the upper 32bits of the offset registers to contain garbage bits that will cause the address calculations to produce incorrect (unaddressable) results. --- runtime/compiler/p/codegen/J9TreeEvaluator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/compiler/p/codegen/J9TreeEvaluator.cpp b/runtime/compiler/p/codegen/J9TreeEvaluator.cpp index 3e54717f23c..b7273723965 100644 --- a/runtime/compiler/p/codegen/J9TreeEvaluator.cpp +++ b/runtime/compiler/p/codegen/J9TreeEvaluator.cpp @@ -11316,6 +11316,11 @@ static bool inlineIntrinsicInflate(TR::Node *node, TR::CodeGenerator *cg) generateTrg1Src1ImmInstruction(cg, TR::InstOpCode::cmpi4, node, condReg, remainingReg, 0); generateConditionalBranchInstruction(cg, TR::InstOpCode::beq, node, doneLabel, condReg); + // IMPORTANT: The upper 32 bits of a 64-bit register containing an int are undefined. Since the + // indices are being passed in as ints, we must ensure that their upper 32 bits are not garbage. + generateTrg1Src1Instruction(cg, TR::InstOpCode::extsw, node, inputOffsetReg, inputOffsetReg); + generateTrg1Src1Instruction(cg, TR::InstOpCode::extsw, node, outputOffsetReg, outputOffsetReg); + /* * Determine the address of the first byte to read either by loading from dataAddr or adding the header size. * This is followed by adding in the offset.