@@ -179,6 +179,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
179
179
180
180
fn persist_new_channel ( & self , funding_txo : OutPoint , monitor : & ChannelMonitor < ChannelSigner > , _update_id : MonitorUpdateId ) -> chain:: ChannelMonitorUpdateStatus {
181
181
let key = format ! ( "{}_{}" , funding_txo. txid. to_hex( ) , funding_txo. index) ;
182
+ debug_assert ! ( key. len( ) > 65 ) ;
182
183
match self . write (
183
184
CHANNEL_MONITOR_PERSISTENCE_NAMESPACE ,
184
185
CHANNEL_MONITOR_PERSISTENCE_SUB_NAMESPACE ,
@@ -191,6 +192,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
191
192
192
193
fn update_persisted_channel ( & self , funding_txo : OutPoint , _update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > , _update_id : MonitorUpdateId ) -> chain:: ChannelMonitorUpdateStatus {
193
194
let key = format ! ( "{}_{}" , funding_txo. txid. to_hex( ) , funding_txo. index) ;
195
+ debug_assert ! ( key. len( ) > 65 ) ;
194
196
match self . write (
195
197
CHANNEL_MONITOR_PERSISTENCE_NAMESPACE ,
196
198
CHANNEL_MONITOR_PERSISTENCE_SUB_NAMESPACE ,
@@ -216,6 +218,13 @@ where
216
218
for stored_key in kv_store. list (
217
219
CHANNEL_MONITOR_PERSISTENCE_NAMESPACE , CHANNEL_MONITOR_PERSISTENCE_SUB_NAMESPACE ) ?
218
220
{
221
+ debug_assert ! ( stored_key. len( ) > 65 ) ;
222
+ if stored_key. len ( ) < 65 {
223
+ return Err ( io:: Error :: new (
224
+ io:: ErrorKind :: InvalidData ,
225
+ "Stored key has invalid length" ) ) ;
226
+ }
227
+
219
228
let txid = Txid :: from_hex ( stored_key. split_at ( 64 ) . 0 ) . map_err ( |_| {
220
229
io:: Error :: new ( io:: ErrorKind :: InvalidData , "Invalid tx ID in stored key" )
221
230
} ) ?;
0 commit comments