Skip to content

Commit

Permalink
Fix offset calculation for external plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed May 8, 2024
1 parent 65c5d8a commit ba777c9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions programs/mpl-core/src/processor/update_external_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,21 @@ fn process_update_external_plugin<'a, T: DataBlob + SolanaAccount>(
// Move offsets for existing registry records.
for record in &mut plugin_registry.external_registry {
if registry_record.offset < record.offset {
record
.offset
.checked_add(size_diff as usize)
let new_offset = (record.offset as isize)
.checked_add(size_diff)
.ok_or(MplCoreError::NumericalOverflow)?;

record.offset = new_offset as usize;
}
}

for record in &mut plugin_registry.registry {
if registry_record.offset < record.offset {
record
.offset
.checked_add(size_diff as usize)
let new_offset = (record.offset as isize)
.checked_add(size_diff)
.ok_or(MplCoreError::NumericalOverflow)?;

record.offset = new_offset as usize;
}
}

Expand Down

0 comments on commit ba777c9

Please sign in to comment.