Details
-
New Feature
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
3.3, 3.4
-
None
Description
STMT_ATTR_CB_RESULT lets an application receive the raw binary-protocol data of each column instead of having C/C fill a bind buffer. The callback gets a pointer to the current position in the row (unsigned char **row) but no information about where the row data ends. A callback therefore cannot validate the data it parses. Length-encoded values (net_field_length), fixed-size integers and floats, and temporal values are all read without any way to check that enough bytes remain. Connector/Python’s callback is one example of an implementation that cannot be made memory-safe with the current API.
Problem
The callback parses data supplied by the server. With a truncated or malformed row, for example a length-encoded prefix announcing more bytes than the packet contains, or a DATETIME with an invalid length byte, the callback reads past the end of the buffer. The result is an out-of-bounds read: potential information disclosure or a crash in the client process. Applications cannot work around this, because the packet boundary is not part of the public API and relying on internal structures is not viable.
Proposed solution
Add a new statement attribute, STMT_ATTR_CB_RESULT_EX, with a callback type that includes an end pointer and a return value: