Skip to content

Commit 99fb980

Browse files
committed
mysql: Parse incoming optimized TIME binary format
When sending a `TIME` value over the binary protocol (a prepared statement), if the value is '00:00:00', the client may send an optimized value by setting the byte length to 0 and sending no bytes. See the mysql developer docs [0], section `ProtocolBinary::MYSQL_TYPE_TIME`. We weren't handling this optimization case and would fail because we expected bytes in the buffer, but there were none. [0] https://dev.mysql.com/doc/dev/mysql-server/latest/ page_protocol_binary_resultset.html Fixes: REA-5962 Release-Note-Core: Correctly handle incoming optimized `TIME` binary format values when the value is '00:00:00'. Change-Id: I8c6c7b33de540e6360a0ae5988c06f25e517be4d Reviewed-on: https://gerrit.readyset.name/c/readyset/+/10333 Reviewed-by: Michael Zink <michael.z@readyset.io> Tested-by: Buildkite CI
1 parent 8aa11f3 commit 99fb980

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mysql-srv/src/value/decode.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ impl<'a> TryFrom<Value<'a>> for MySqlTime {
277277
type Error = MsqlSrvError;
278278
fn try_from(val: Value<'a>) -> Result<MySqlTime, Self::Error> {
279279
if let ValueInner::Time(mut v) = val.0 {
280+
// if there's no bytes, it means the client sent an "optimized"
281+
// time value of '00:00:00'.
282+
// see https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_binary_resultset.html
283+
if v.is_empty() {
284+
return Ok(Default::default());
285+
}
286+
280287
let is_positive = v.read_u8()? == 0; // sign: 1 negative, 0 positive
281288
let d = v.read_u32::<LittleEndian>()? as u16;
282289
let h = v.read_u8()? as u16;

0 commit comments

Comments
 (0)