Skip to content

feat(ok): add correct handling of ok packets in MYSQL implementation #3910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xfourzerofour
Copy link

As per the Mysql documentation, OK and EOF packets have the following structure

OK: header = 0 and length of packet >= 7
EOF: header = 0xfe and length of packet < 8

Right now we are checking to see if the packet is smaller than 9 which is fine for most cases however there are some projects that implement the MySQL protocol which include information in the packet (e.g query speed, rows returned in human readable text)

https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_ok_packet.html

For example in the project manticore https://github.com/manticoresoftware/manticoresearch (Which is why I found this bug) their ok packet to designate the end of the data will include more information. This would result in sqlx treating the the OK packet as a text field due to the fact that the length is larger than 8.

Search error: encountered unexpected or invalid data: buffer exhausted when reading data for column MySqlColumn { ordinal: 0, name: id, type_info: MySqlTypeInfo { type: LongLong, flags: ColumnFlags(0x0), max_size: Some(20) }, flags: Some(ColumnFlags(0x0)) }; decoded length is 3251880405938339840, but only 32 bytes remain in buffer. Malformed packet or protocol error? (sqlx_mysql::protocol::text::row:27)
b"\0\0\0\x02\0\0\0"
b"\0\0\0\x02\0\0\0"
b"\x03"
b"\x03def\tManticore\0\0\x02id\x02id\x0c!\0\x14\0\0\0\x08\0\0\0\0\0"
b"\x03def\tManticore\0\0\x04name\x04name\x0c!\0\xff\0\0\0\xfe\0\0\0\0\0"
b"\x03def\tManticore\0\0\x0bdescription\x0bdescription\x0c!\0\xff\0\0\0\xfe\0\0\0\0\0"
b"\x0291\x05Tacos\x17All the best taco spots"
b"\x0292\x05Tacos\x17All the best taco spots"
b"\x0293\x05Tacos\x17All the best taco spots"
b"\x0294\x05Tacos\x17All the best taco spots"
b"\x0295\x05Tacos\x17All the best taco spots"
b"\x0290\x05Tacos\x17All the best taco spots"
b"\xfe\0\0\x02\0\0\0!--- 6 out of 6 results in 3ms ---" <---- this part

There is a larger deep dive in the manticore project here but the gist is that the current decoder skips the optional info field in valid mysql ok packets

@0xfourzerofour 0xfourzerofour changed the title feat(ok): add correct handling of ok packets feat(ok): add correct handling of ok packets in MYSQL implementation Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant