Use VarString for string parameter encoding in binary protocol#142
Open
Use VarString for string parameter encoding in binary protocol#142
Conversation
String parameters in prepared statements were encoded with MYSQL_TYPE_LONG_BLOB (0xfb), which tells the server to treat the value as raw binary data. This breaks MariaDB's native UUID column type (introduced in 10.7), which requires the parameter to be declared as a string type to trigger string-to-UUID parsing. Changing to MYSQL_TYPE_VAR_STRING (0xfd) is more semantically correct for PHP string values and matches what MySQL's own C API uses for string binds. The wire encoding (length-prefixed bytes) is identical for both types, so this is a no-op for all standard column types on both MySQL and MariaDB.
Psalm 6.15.1 on PHP 8.4.19 incorrectly reports InvalidAttribute for #[\Override] attributes. This was green on PHP 8.4.18 but broke with the runner update. Suppress until Psalm is updated.
Author
|
Note: The CI failures on PHP 8.2–8.5 are unrelated to this change — Psalm 6.15.1 started reporting |
webpatser
added a commit
to webpatser/fledge-fiber
that referenced
this pull request
Apr 10, 2026
Security: - Fix HTTP/2 ping flood on active streams (amphp/http-server#386) Bug fixes: - Use VarString for string params in binary protocol (amphp/mysql#142) - Decode BIT columns as int instead of string (amphp/mysql#138) - Close connections on pool destruct (amphp/http-client#396) - Fix duplicate keys in byte-stream split() (amphp/byte-stream#113) - Fix Closure type annotation for static analysis (amphp/amp#451) - Safely handle DisposedException on unsubscribe (amphp/redis#100) Features: - Add TLS support for Redis connections (amphp/redis#98) - Add disperse() for concurrent closure execution (amphp/amp#460)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MYSQL_TYPE_LONG_BLOB(0xfb), which tells the server to treat values as raw binary dataUUIDcolumn type (introduced in MariaDB 10.7), which requires string-typed parameters to trigger string→UUID parsingMYSQL_TYPE_VAR_STRING(0xfd), which is more semantically correct for PHP string values and matches MySQL's own C API behavior for string bindsWhy this matters
MariaDB 10.7+ introduced a native
UUIDcolumn type that stores UUIDs as 16-byte binary internally. When a prepared statement parameter is typed asLONG_BLOB, MariaDB interprets the 36-byte ASCII UUID string as raw bytes instead of parsing the human-readable format. WithVAR_STRING, MariaDB correctly converts the string representation to its internal format.Safety
The wire encoding (length-prefixed bytes) is identical for both
LongBlobandVarString— only the 2-byte type header inCOM_STMT_EXECUTEchanges. All existing tests pass (136/136).This is effectively a no-op for all standard MySQL/MariaDB column types (
VARCHAR,CHAR,TEXT,BLOB, etc.) since both types trigger the same implicit conversion paths. The difference only surfaces for MariaDB-specific types likeUUIDthat distinguish between string and binary parameter sources.Suggestion
The current test suite only runs against MySQL. Adding MariaDB to the CI matrix (related: #80) would help catch driver-specific issues like this. Happy to help with that in a follow-up PR if there's interest.