-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
skip empty string for start position #4596
skip empty string for start position #4596
Conversation
92284c4
to
81438f5
Compare
Again not sure why ci/circleci test -- TestServer_Query_Aggregates_FloatMany failed as below:
I have tried to execute test locally as well as docker, success without errors... UPDATED: the test seems passed now |
check this function |
@oiooj yup I'm doing similar checking, but there is some minor different:
and I'm trying to skip for uint = 0 |
bufLength := len(buf) | ||
|
||
for { | ||
if bufLength > start && buf[start] == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I had filled the buffer with some other non-zero value, which was not a valid character? Is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is possible if someone purposely do it programmatically.
This fixes is more like a prevention for a programmer's mistake, eg, buffer helps us to generate empty string without we knowing it, and it is not visible until the result from len(key)
.is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is fair enough.
On Wed, Oct 28, 2015 at 11:14 AM, Lim Chee Hau notifications@github.com
wrote:
In models/points.go
#4596 (comment):@@ -741,6 +741,16 @@ func scanLine(buf []byte, i int) (int, []byte) {
start := i
quoted := false
fields := false
- bufLength := len(buf)
- for {
if bufLength > start && buf[start] == 0 {
I think it is possible if someone purposely do it programmatically.
This fixes is more like a prevention for a programmer's mistake, eg,
buffer helps us to generate empty string without we knowing it, and it is
not visible until the result from len(key).is called.—
Reply to this email directly or view it on GitHub
https://github.com/influxdb/influxdb/pull/4596/files#r43296011.
Thanks @ch33hau. The fix for this is in the wrong place though. It should be:
Because https://github.com/influxdb/influxdb/blob/master/models/points.go#L139 is where the start position within the line is determined. |
@@ -1509,3 +1510,25 @@ func TestPrecisionString(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func Test_ParsePointsStringWithExtraBuffer(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the other tests in the file, can you remove the _
since the others do not follow this naming convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
81438f5
to
f13af15
Compare
+1, makes sense to me, but waiting for confirmation from @jwilder |
skip empty string for start position
Thanks @ch33hau! |
Hi,
I found out that scanLine() in models/points.go doesn't filter empty string (uint8 = 0) for start position.
This will introduce some weird issues if the input is made from a large buffer, the Key() from first point gonna be a very large string with all the empty string due to the invalid start position.
One of the obvious example is, if you change the value from uswest10 to uswest1 in https://github.com/influxdb/influxdb/blob/master/tsdb/engine/wal/wal_test.go#L327, the test will be failed due to this issue (only uswest1 will fail, uswest2 until uswest100 working fine). The reason is the first key is a large string (350000*uint8 + "cpu,host=A,region=uswest1"), it return no result when we pass in the valid key "cpu,host=A,region=uswest1" to lookup value from map (string comparison failed).
I have also created a test for points_test.go, this test gonna be failed without the new changes.
Sorry if my explanation is not clear enough.