File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -481,6 +481,19 @@ impl RequesterContext {
481481 error ! ( "!!! receive_large_response: large message size too small !!!\n " ) ;
482482 return Err ( SPDM_STATUS_INVALID_MSG_FIELD ) ;
483483 }
484+
485+ // Early check whether large message size is too large to be received in chunks.
486+ let data_transfer_size = config:: SPDM_DATA_TRANSFER_SIZE ;
487+ let max_large_response_size = ( data_transfer_size
488+ - SPDM_VERSION_1_2_OFFSET_OF_SPDM_CHUNK_IN_CHUNK_RESPONSE )
489+ * ( u16:: MAX as usize - 1 )
490+ + data_transfer_size
491+ - SPDM_VERSION_1_2_OFFSET_OF_RESPONSE_OF_LARGE_REQUEST_IN_CHUNK_SEND_ACK ;
492+ if large_message_size as usize > max_large_response_size {
493+ error ! ( "!!! receive_large_response: request too large to receive in chunks !!!\n " ) ;
494+ return Err ( SPDM_STATUS_INVALID_MSG_FIELD ) ;
495+ }
496+
484497 self . common . chunk_context . chunk_message_size =
485498 large_message_size as usize ;
486499 } else {
Original file line number Diff line number Diff line change @@ -882,15 +882,25 @@ impl ResponderContext {
882882 let max_chunk_size = ( config:: SPDM_DATA_TRANSFER_SIZE
883883 - SPDM_VERSION_1_2_OFFSET_OF_SPDM_CHUNK_IN_FIRST_CHUNK_SEND )
884884 as u32 ;
885+
886+ // Early check whether large message size is too large to be received in chunks.
887+ let data_transfer_size = config:: SPDM_DATA_TRANSFER_SIZE ;
888+ let max_large_request_size = ( data_transfer_size
889+ - SPDM_VERSION_1_2_OFFSET_OF_SPDM_CHUNK_IN_CHUNK_SEND )
890+ * ( u16:: MAX as usize - 1 )
891+ + data_transfer_size
892+ - SPDM_VERSION_1_2_OFFSET_OF_SPDM_CHUNK_IN_FIRST_CHUNK_SEND ;
893+
885894 if chunk_send_request. chunk_seq_num != 0
886895 || !( config:: SPDM_MIN_DATA_TRANSFER_SIZE ..=config:: MAX_SPDM_MSG_SIZE )
887896 . contains ( & large_message_size)
897+ || large_message_size > max_large_request_size
888898 || chunk_send_request
889899 . chunk_sender_attributes
890900 . contains ( SpdmChunkSenderAttributes :: LAST_CHUNK )
891901 || chunk_send_request. chunk_size > max_chunk_size
892902 {
893- error ! ( "!!! invalid chunk send request, first chunk send is expected !!!\n " ) ;
903+ error ! ( "!!! invalid chunk send request, first chunk send is expected or request contains illegal data !!!\n " ) ;
894904 self . write_spdm_error ( SpdmErrorCode :: SpdmErrorInvalidRequest , 0 , writer) ;
895905 return (
896906 Err ( SPDM_STATUS_INVALID_STATE_PEER ) ,
You can’t perform that action at this time.
0 commit comments