@@ -396,7 +396,7 @@ private int ListObjectKeys(RespCommand command)
396396 RespCommand . LSET => SingleKey ( StoreType . Object , LockType . Exclusive ) ,
397397
398398 RespCommand . LMOVE => ListKeys ( 2 , StoreType . Object , LockType . Exclusive ) ,
399- RespCommand . LMPOP => ListReadKeysWithCount ( LockType . Exclusive ) ,
399+ RespCommand . LMPOP => ListReadKeysWithCount ( LockType . Exclusive , mandatoryArgs : 1 ) ,
400400 RespCommand . LPOS => SingleKey ( StoreType . Object , LockType . Shared ) ,
401401 RespCommand . LPUSHX => SingleKey ( StoreType . Object , LockType . Exclusive ) ,
402402 RespCommand . RPOPLPUSH => ListKeys ( 2 , StoreType . Object , LockType . Exclusive ) ,
@@ -498,17 +498,21 @@ private int ListKeys(int inputCount, StoreType storeType, LockType type)
498498 /// <summary>
499499 /// Returns a list of keys for LMPOP command
500500 /// </summary>
501- private int ListReadKeysWithCount ( LockType type , bool isObject = true )
501+ private int ListReadKeysWithCount ( LockType type , bool isObject = true , int mandatoryArgs = 0 )
502502 {
503- var numKeysArg = respSession . GetCommandAsArgSlice ( out var success ) ;
504- if ( ! success ) return - 2 ;
503+ if ( respSession . parseState . Count == 0 )
504+ return - 2 ;
505+ var numKeysArg = respSession . parseState . GetArgSliceByRef ( 0 ) ;
505506
506- if ( ! NumUtils . TryParse ( numKeysArg . ReadOnlySpan , out int numKeys ) ) return - 2 ;
507+ if ( ! NumUtils . TryParse ( numKeysArg . ReadOnlySpan , out int numKeys ) )
508+ return - 2 ;
507509
508- for ( var i = 0 ; i < numKeys ; i ++ )
510+ if ( numKeys + mandatoryArgs + 1 > respSession . parseState . Count )
511+ return - 2 ;
512+
513+ for ( var i = 1 ; i < numKeys + 1 ; i ++ )
509514 {
510- var key = respSession . GetCommandAsArgSlice ( out success ) ;
511- if ( ! success ) return - 2 ;
515+ var key = respSession . parseState . GetArgSliceByRef ( i ) ;
512516 SaveKeyEntryToLock ( key , isObject , type ) ;
513517 SaveKeyArgSlice ( key ) ;
514518 }
0 commit comments