fix: prevent panic on multi-byte UTF-8 in SQL obfuscation#11792
Open
AruneshDwivedi wants to merge 1 commit into
Open
fix: prevent panic on multi-byte UTF-8 in SQL obfuscation#11792AruneshDwivedi wants to merge 1 commit into
AruneshDwivedi wants to merge 1 commit into
Conversation
When the SQL tokenizer returns an error location that falls in the middle of a multi-byte UTF-8 character (e.g., Chinese, Japanese), byte_offset would not be at a char boundary, causing a panic at &sql[..byte_offset]. Use str::floor_char_boundary() to clamp the offset to the nearest valid char boundary before slicing. Fixes deepflowio#11791
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.
Problem
When SQL obfuscation (
obfuscate_protocols) is enabled for MySQL or PostgreSQL,and the captured SQL contains multi-byte UTF-8 characters (Chinese, Japanese, etc.),
the deepflow-agent panics with:
This causes the agent to enter CrashLoopBackOff, breaking all observability
data collection on that node.
Root Cause
When the SQL tokenizer returns an error location, the code computes a
byte_offsetfrom the line/column position. This offset can land in themiddle of a multi-byte UTF-8 character. Slicing a
strat a non-char-boundaryindex is undefined behavior and causes a panic in Rust.
Fix
Use
str::floor_char_boundary()(stabilized in Rust 1.73) to clamp thebyte offset to the nearest valid character boundary before slicing.
Testing
Reproduction: enable
obfuscate_protocolsfor MySQL/PostgreSQL and runqueries containing multi-byte UTF-8 characters. Before the fix, the agent
panics. After the fix, SQL is correctly obfuscated.
Fixes #11791