Skip to content

Conversation

@ivan-golubev
Copy link
Contributor

@ivan-golubev ivan-golubev commented Dec 5, 2025

Description

Fix for the stack-buffer-overflow when using the FieldInfo like this:

 inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(AppStateSpec_AppState*) noexcept {
  winrt::Microsoft::ReactNative::FieldMap fieldMap {
      {L"app_state", &AppStateSpec_AppState::app_state},
  	// ^^^^^^^^^ when constructing the std::pair, temporary stack variables are created.
  };
  return fieldMap;
 }

but here in react-native-windows\vnext\Microsoft.ReactNative.Cxx\StructInfo.h the FieldInfo is trying to dereference and store data from a pointer (&fieldPtr) that points to a temporary object on the stack:

m_fieldPtrStore{*reinterpret_cast<uintptr_t *>(&fieldPtr)}

AddressSanitizer detects the stack-buffer-overflow (accessing memory past the temporary's lifetime) and terminates the process. Instead, we avoid double indirection by using a memcopy.

Microsoft Reviewers: Open in CodeFlow

Fix for the stack-buffer-overflow when using the FieldInfo like this:
 inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(AppStateSpec_AppState*) noexcept {
  winrt::Microsoft::ReactNative::FieldMap fieldMap {
      {L"app_state", &AppStateSpec_AppState::app_state},
  	// ^^^^^^^^^ when constructing the std::pair, temporary stack variables are created.
  };
  return fieldMap;
 }

but here in react-native-windows\vnext\Microsoft.ReactNative.Cxx\StructInfo.h the FieldInfo is trying to dereference and store data from a pointer (&fieldPtr) that points to a temporary object on the stack:
m_fieldPtrStore{*reinterpret_cast<uintptr_t *>(&fieldPtr)}

AddressSanitizer detects the stack-buffer-overflow (accessing memory past the temporary's lifetime) and terminates the process.
Instead, we avoid double indirection by using a memcopy.
@ivan-golubev ivan-golubev requested a review from a team as a code owner December 5, 2025 17:33
Copy link
Member

@vmoroz vmoroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vmoroz
Copy link
Member

vmoroz commented Dec 5, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ivan-golubev
Copy link
Contributor Author

ivan-golubev commented Dec 6, 2025

@microsoft-github-policy-service agree company="Meta"

1 similar comment
@ivan-golubev
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Meta"

@vineethkuttan
Copy link
Contributor

/azp run PR

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vineethkuttan vineethkuttan added the AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) label Dec 6, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit e990ad5 into microsoft:main Dec 6, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants