Skip to content

Commit 694152f

Browse files
Fix stack corruption in TryEmitExportParameterArgument
LoadArgument + LoadConstantI4(0) were emitted unconditionally before the switch statement. When exportKind is Unspecified (the default for parameters without [ExportParameter] attributes), the method returned false without consuming those two stack values, corrupting the IL evaluation stack. Move the LoadArgument + LoadConstantI4(0) into each case block so they are only emitted when the method will also emit the consuming Call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f08ecb9 commit 694152f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ExportMethodDispatchEmitter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,25 @@ void ThrowIfUnsupportedManagedType (string managedTypeName)
284284

285285
bool TryEmitExportParameterArgument (InstructionEncoder encoder, ExportParameterKindInfo exportKind, int argumentIndex)
286286
{
287-
encoder.LoadArgument (argumentIndex);
288-
encoder.LoadConstantI4 (0);
289-
290287
switch (exportKind) {
291288
case ExportParameterKindInfo.InputStream:
289+
encoder.LoadArgument (argumentIndex);
290+
encoder.LoadConstantI4 (0);
292291
encoder.Call (_context.InputStreamInvokerFromJniHandleRef);
293292
return true;
294293
case ExportParameterKindInfo.OutputStream:
294+
encoder.LoadArgument (argumentIndex);
295+
encoder.LoadConstantI4 (0);
295296
encoder.Call (_context.OutputStreamInvokerFromJniHandleRef);
296297
return true;
297298
case ExportParameterKindInfo.XmlPullParser:
299+
encoder.LoadArgument (argumentIndex);
300+
encoder.LoadConstantI4 (0);
298301
encoder.Call (_context.XmlPullParserReaderFromJniHandleRef);
299302
return true;
300303
case ExportParameterKindInfo.XmlResourceParser:
304+
encoder.LoadArgument (argumentIndex);
305+
encoder.LoadConstantI4 (0);
301306
encoder.Call (_context.XmlResourceParserReaderFromJniHandleRef);
302307
return true;
303308
default:

0 commit comments

Comments
 (0)