From 35fbe20cb997cc80b37105c40770f6ba77afce9d Mon Sep 17 00:00:00 2001 From: Vincent Riemer <1398555+vincentriemer@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:32:04 -0700 Subject: [PATCH] Adjust RawPropsPropNameLength's type to account for increased number of props (#39008) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39008 Changelog: [Internal] - Adjust RawPropsPropNameLength's type to account for increased number of props While investigating why we needed to back out D48288752 I discovered that the root cause was that the `items_` vector in `RawProsKeyMap` was now a size greater than 255 which becomes an issue because `items_`'s indices are statically cast to `RawPropsPropNameLength` (previously alias to `uint8_t`). This diff updates `RawPropsPropNameLength` to be an alias to `uint16_t` so the current issue is resolved as well as adding an assert to ensure (however unlikely) that this happens again. Reviewed By: rozele Differential Revision: D48331909 fbshipit-source-id: 5433b27d789ed0bf4475e1649041ff9f1fef1d33 --- .../ReactCommon/react/renderer/core/RawPropsKeyMap.cpp | 2 ++ .../ReactCommon/react/renderer/core/RawPropsParser.cpp | 1 + .../ReactCommon/react/renderer/core/RawPropsPrimitives.h | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp index d4a8d78e228851..67ce4f12989124 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp @@ -38,6 +38,8 @@ void RawPropsKeyMap::insert( item.value = value; key.render(item.name, &item.length); items_.push_back(item); + react_native_assert( + items_.size() < std::numeric_limits::max()); } void RawPropsKeyMap::reindex() noexcept { diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp index d78f83ce125da9..5e6f72f0c786ea 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp @@ -42,6 +42,7 @@ RawValue const *RawPropsParser::at( // This is not thread-safe part; this happens only during initialization of // a `ComponentDescriptor` where it is actually safe. keys_.push_back(key); + react_native_assert(size < std::numeric_limits::max()); nameToIndex_.insert(key, static_cast(size)); return nullptr; } diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawPropsPrimitives.h b/packages/react-native/ReactCommon/react/renderer/core/RawPropsPrimitives.h index 18fac05b91b607..dfd75a8f9b7400 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawPropsPrimitives.h +++ b/packages/react-native/ReactCommon/react/renderer/core/RawPropsPrimitives.h @@ -15,11 +15,11 @@ namespace facebook::react { /* * Type used to represent an index of some stored values in small arrays. */ -using RawPropsValueIndex = uint8_t; +using RawPropsValueIndex = uint16_t; static_assert( - sizeof(RawPropsValueIndex) == 1, - "RawPropsValueIndex must be one byte size."); -using RawPropsPropNameLength = uint8_t; + sizeof(RawPropsValueIndex) == 2, + "RawPropsValueIndex must be two byte size."); +using RawPropsPropNameLength = uint16_t; using RawPropsPropNameHash = uint32_t; /*