File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
sqlx-mysql/src/protocol/response Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ impl ProtocolDecode<'_> for OkPacket {
2626
2727 let affected_rows = buf. get_uint_lenenc ( ) ;
2828 let last_insert_id = buf. get_uint_lenenc ( ) ;
29+
30+ if buf. remaining ( ) < 4 {
31+ return Err ( err_protocol ! (
32+ "OK_Packet too short: expected at least 4 more bytes for status+warnings, got {}" ,
33+ buf. remaining( )
34+ ) ) ;
35+ }
36+
2937 let status = Status :: from_bits_truncate ( buf. get_u16_le ( ) ) ;
3038 let warnings = buf. get_u16_le ( ) ;
3139
@@ -76,3 +84,11 @@ fn test_decode_ok_packet_with_extended_info() {
7684 assert_eq ! ( p. warnings, 1 ) ;
7785 assert ! ( p. status. contains( Status :: SERVER_STATUS_AUTOCOMMIT ) ) ;
7886}
87+
88+ #[ test]
89+ fn test_decode_ok_packet_truncated ( ) {
90+ const DATA : & [ u8 ] = b"\x00 \x00 \x00 \x01 " ;
91+
92+ let err = OkPacket :: decode ( DATA . into ( ) ) . unwrap_err ( ) ;
93+ assert ! ( matches!( err, Error :: Protocol ( _) ) , "{err}" ) ;
94+ }
You can’t perform that action at this time.
0 commit comments