diff options
| author | bors <bors@rust-lang.org> | 2024-06-01 12:24:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-01 12:24:44 +0000 |
| commit | acaf0aeed0dfbfc4be9f996344e2c5f294cf5794 (patch) | |
| tree | ce4b494d9c7f2b8c5d43a7341278cca937d0ed84 /compiler/rustc_mir_transform/src | |
| parent | 05965ae238403d8c141170b411245a62aa046240 (diff) | |
| parent | d3c8e6788cfbcc64ab7710cab7a56e276e7d5a7a (diff) | |
| download | rust-acaf0aeed0dfbfc4be9f996344e2c5f294cf5794.tar.gz rust-acaf0aeed0dfbfc4be9f996344e2c5f294cf5794.zip | |
Auto merge of #125821 - Luv-Ray:issue#121126, r=fee1-dead
Check index `value <= 0xFFFF_FF00`
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
-->
fixes #121126
check `idx <= FieldIdx::MAX_AS_U32` before calling `FieldIdx::from_u32` to avoid panic.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/known_panics_lint.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 9ba22870403..8b46658b322 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -102,8 +102,12 @@ impl<'tcx> Value<'tcx> { } (PlaceElem::Index(idx), Value::Aggregate { fields, .. }) => { let idx = prop.get_const(idx.into())?.immediate()?; - let idx = prop.ecx.read_target_usize(idx).ok()?; - fields.get(FieldIdx::from_u32(idx.try_into().ok()?)).unwrap_or(&Value::Uninit) + let idx = prop.ecx.read_target_usize(idx).ok()?.try_into().ok()?; + if idx <= FieldIdx::MAX_AS_U32 { + fields.get(FieldIdx::from_u32(idx)).unwrap_or(&Value::Uninit) + } else { + return None; + } } ( PlaceElem::ConstantIndex { offset, min_length: _, from_end: false }, |
