trilogy-libraries / trilogy

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.
MIT License
697 stars 68 forks source link

Don't confuse length encoded int with EOF #179

Open composerinteralia opened 5 months ago

composerinteralia commented 5 months ago

Prior to this commit a row starting with a field with length 2 ** 24 or higher would get interpreted as an EOF and we'd fail with:

Trilogy::QueryError: trilogy_read_row: TRILOGY_EXTRA_DATA_IN_PACKET

rows are sent as a series of length encoded strings. These are strings prefixed by a length encoded integer, where 0xFE is the prefix byte for an 8 byte integer.

After all the rows are sent, we get a OK/EOF packet beginning with 0xFE.

The way to tell the OK/EOF apart from an 8-byte length-encoded int is by checking that the length of the whole payload is < 9 (i.e. there isn't enough room for an 8-byte int).

We were doing the < 9 check for the deprecated EOF packets, but not for the newer OK packets.