From 4e642d45cfd403cbf1f1fdf5d536f3be2ae5ccaf Mon Sep 17 00:00:00 2001 From: Younies Mahmoud Date: Thu, 16 Nov 2023 21:44:44 +0100 Subject: [PATCH] Fix #3900: return an error if the index is greater than MAX_PLACE_HOLDER_INDEX (#4318) --- .../src/transform/cldr/currency/mod.rs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/provider/datagen/src/transform/cldr/currency/mod.rs b/provider/datagen/src/transform/cldr/currency/mod.rs index afd24e6ec2f..b7749f25d0d 100644 --- a/provider/datagen/src/transform/cldr/currency/mod.rs +++ b/provider/datagen/src/transform/cldr/currency/mod.rs @@ -141,8 +141,6 @@ fn extract_currency_essentials<'data>( PlaceholderValue::ISO } else { let index = place_holders.len() as u16; - //TODO(#3900): remove this assert and return an error instead. - assert!(index <= MAX_PLACE_HOLDER_INDEX); place_holders.push(short_place_holder.as_str()); place_holders_checker_map.insert(short_place_holder.as_str(), index); PlaceholderValue::Index(index) @@ -157,14 +155,28 @@ fn extract_currency_essentials<'data>( PlaceholderValue::ISO } else { let index = place_holders.len() as u16; - //TODO(#3900): remove this assert and return an error instead. - assert!(index <= MAX_PLACE_HOLDER_INDEX); place_holders.push(narrow_place_holder.as_ref()); place_holders_checker_map.insert(narrow_place_holder.as_str(), index); PlaceholderValue::Index(index) } }); + // Ensure that short_place_holder_index and narrow_place_holder_index do not exceed MAX_PLACE_HOLDER_INDEX. + if let Some(PlaceholderValue::Index(index)) = short_place_holder_index { + if index > MAX_PLACE_HOLDER_INDEX { + return Err(DataError::custom( + "short_place_holder_index exceeded MAX_PLACE_HOLDER_INDEX", + )); + } + } + if let Some(PlaceholderValue::Index(index)) = narrow_place_holder_index { + if index > MAX_PLACE_HOLDER_INDEX { + return Err(DataError::custom( + "narrow_place_holder_index exceeded MAX_PLACE_HOLDER_INDEX", + )); + } + } + let iso_string = iso.try_into_tinystr().unwrap().to_string(); let short_pattern_standard: PatternSelection = if standard_alpha_next_to_number.is_empty() {