@@ -7258,8 +7258,20 @@ where
7258
7258
impl Writeable for VecDeque < ( Event , Option < EventCompletionAction > ) > {
7259
7259
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
7260
7260
( self . len ( ) as u64 ) . write ( w) ?;
7261
- for elem in self . iter ( ) {
7262
- elem. write ( w) ?;
7261
+ for ( event, action) in self . iter ( ) {
7262
+ event. write ( w) ?;
7263
+ action. write ( w) ?;
7264
+ #[ cfg( debug_assertions) ] {
7265
+ // Events are MaybeReadable, in some cases indicating that they shouldn't actually
7266
+ // be persisted and are regenerated on restart. However, if such an event has a
7267
+ // post-event-handling action we'll write nothing for the event and would have to
7268
+ // either forget the action or fail on deserialization (which we do below). Thus,
7269
+ // check that the event is sane here.
7270
+ let event_encoded = event. encode ( ) ;
7271
+ let event_read: Option < Event > =
7272
+ MaybeReadable :: read ( & mut & event_encoded[ ..] ) . unwrap ( ) ;
7273
+ if action. is_some ( ) { assert ! ( event_read. is_some( ) ) ; }
7274
+ }
7263
7275
}
7264
7276
Ok ( ( ) )
7265
7277
}
@@ -7268,14 +7280,16 @@ impl Readable for VecDeque<(Event, Option<EventCompletionAction>)> {
7268
7280
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
7269
7281
let len: u64 = Readable :: read ( reader) ?;
7270
7282
const MAX_ALLOC_SIZE : u64 = 1024 * 16 ;
7271
- let mut events = VecDeque :: with_capacity ( cmp:: min (
7283
+ let mut events: Self = VecDeque :: with_capacity ( cmp:: min (
7272
7284
MAX_ALLOC_SIZE /mem:: size_of :: < ( events:: Event , Option < EventCompletionAction > ) > ( ) as u64 ,
7273
7285
len) as usize ) ;
7274
7286
for _ in 0 ..len {
7275
7287
let ev_opt = MaybeReadable :: read ( reader) ?;
7276
7288
let action = Readable :: read ( reader) ?;
7277
7289
if let Some ( ev) = ev_opt {
7278
7290
events. push_back ( ( ev, action) ) ;
7291
+ } else if action. is_some ( ) {
7292
+ return Err ( DecodeError :: InvalidValue ) ;
7279
7293
}
7280
7294
}
7281
7295
Ok ( events)
0 commit comments