Skip to content

Commit defd51b

Browse files
authored
Enforce string limits for deserialization (#4567)
1 parent 757d42d commit defd51b

File tree

13 files changed

+554
-33
lines changed

13 files changed

+554
-33
lines changed

crates/bin/pd/src/migrate.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod testnet72;
1010
mod testnet74;
1111
mod testnet76;
1212
mod testnet77;
13+
mod testnet78;
1314

1415
use anyhow::{ensure, Context};
1516
use penumbra_governance::StateReadExt;
@@ -47,6 +48,9 @@ pub enum Migration {
4748
/// Testnet-77 migration:
4849
/// - Reset the halt bit
4950
Testnet77,
51+
/// Testnet-78 migration:
52+
/// - Truncate various user-supplied `String` fields to a maximum length.
53+
Testnet78,
5054
}
5155

5256
impl Migration {
@@ -72,30 +76,22 @@ impl Migration {
7276
);
7377
tracing::info!("started migration");
7478

79+
// If this is `ReadyToStart`, we need to reset the halt bit and return early.
80+
if let Migration::ReadyToStart = self {
81+
reset_halt_bit::migrate(storage, pd_home, genesis_start).await?;
82+
return Ok(());
83+
}
84+
7585
match self {
76-
Migration::ReadyToStart => {
77-
reset_halt_bit::migrate(storage, pd_home, genesis_start).await?;
78-
return Ok(());
79-
}
8086
Migration::SimpleMigration => {
8187
simple::migrate(storage, pd_home.clone(), genesis_start).await?
8288
}
8389

84-
Migration::Testnet72 => {
85-
testnet72::migrate(storage, pd_home.clone(), genesis_start).await?
86-
}
87-
88-
Migration::Testnet74 => {
89-
testnet74::migrate(storage, pd_home.clone(), genesis_start).await?
90+
Migration::Testnet78 => {
91+
testnet78::migrate(storage, pd_home.clone(), genesis_start).await?
9092
}
91-
92-
Migration::Testnet76 => {
93-
testnet76::migrate(storage, pd_home.clone(), genesis_start).await?
94-
}
95-
Migration::Testnet77 => {
96-
testnet77::migrate(storage, pd_home.clone(), genesis_start).await?
97-
}
98-
};
93+
_ => unreachable!(),
94+
}
9995

10096
if let Some(comet_home) = comet_home {
10197
// TODO avoid this when refactoring to clean up migrations

crates/bin/pd/src/migrate/reset_halt_bit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ pub async fn migrate(
1616
let _ = storage.commit_in_place(delta).await?;
1717
storage.release().await;
1818
tracing::info!("migration completed: halt bit is turned off, chain is ready to start");
19+
1920
Ok(())
2021
}

crates/bin/pd/src/migrate/testnet72.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Contains functions related to the migration script of Testnet72
2-
2+
#![allow(dead_code)]
33
use anyhow;
44
use cnidarium::{Snapshot, StateDelta, StateRead, StateWrite, Storage};
55
use futures::StreamExt as _;

crates/bin/pd/src/migrate/testnet74.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Contains functions related to the migration script of Testnet74
2+
#![allow(dead_code)]
23

34
use anyhow;
45
use cnidarium::{EscapedByteSlice, Snapshot, StateDelta, StateRead, StateWrite, Storage};

crates/bin/pd/src/migrate/testnet76.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Contains functions related to the migration script of Testnet74
2+
#![allow(dead_code)]
23

34
use anyhow;
45
use cnidarium::{Snapshot, StateDelta, Storage};

0 commit comments

Comments
 (0)