fix(plugin-mysql): read MARIADB_CONST_STRING by length to stop JSON detection flicker#1216
Merged
Merged
Conversation
70c6476 to
621c0e5
Compare
5 tasks
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
User reported
audit_log.payloadchevron flickering on rapid Cmd+R refresh. Inspector pane confirmed the column type was alternating betweenjsonandstringacross refreshes — same query, same column, intermittent classification.Root cause
MariaDBPluginConnection.mysqlTypeToStringrecognizes JSON-stored-as-LONGTEXT by reading MariaDB's extended metadata:MARIADB_CONST_STRINGis a length-prefixed buffer ({ const char *str; size_t length; }) — not null-terminated.String(cString:)scans bytes until it hits the next\0, which means it reads past the four bytes of"json"into whatever memory happens to live next in the result-set buffer.When that adjacent memory contained a null byte →
String(cString:)returned"json"→ comparison passed → column taggedJSON→ JSON kind → chevron visible.When that adjacent memory contained non-null bytes →
String(cString:)returned"json…garbage"→ comparison failed → fell through to the type switch → column taggedLONGTEXT→ text kind → no chevron.The contents of the adjacent memory are non-deterministic (depends on what the connector library wrote there for previous rows / fields, allocator alignment padding, etc.), which is why the bug presented as a flicker rather than a consistent failure.
Fix
Read exactly
attr.lengthbytes:Data(bytes:count:)copies exactlycountbytes and stops, so there is no over-read.String(bytes:encoding:)(which SwiftLint prefers over the non-failableString(decoding:as:)) returnsnilon invalid UTF-8, which we want anyway — anything that isn't valid UTF-8 isn't going to be the literal"json"we're looking for.Test plan
tablepro_demo→audit_log.payload: jsonon every refresh, neverstring.payloadcell every refresh.LONGTEXTand use the plain text editor.