mirror of https://github.com/minio/minio.git
select: Fix integer conversion overflow (#10437)
Do not convert float value to integer if it will over/underflow. The comparison cannot be `<=` since rounding may overflow it. Fixes #10436
This commit is contained in:
parent
6a0372be6c
commit
0987069e37
|
@ -18,6 +18,7 @@ package s3select
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -93,6 +94,20 @@ func TestJSONQueries(t *testing.T) {
|
|||
query: `SELECT * from s3object s WHERE 'bar' in s.synonyms[*]`,
|
||||
wantResult: `{"id":0,"title":"Test Record","desc":"Some text","synonyms":["foo","bar","whatever"]}`,
|
||||
},
|
||||
{
|
||||
name: "bignum-1",
|
||||
query: `SELECT id from s3object s WHERE s.id <= 9223372036854775807`,
|
||||
wantResult: `{"id":0}
|
||||
{"id":1}
|
||||
{"id":2}
|
||||
{"id":3}`},
|
||||
{
|
||||
name: "bignum-2",
|
||||
query: `SELECT id from s3object s WHERE s.id >= -9223372036854775808`,
|
||||
wantResult: `{"id":0}
|
||||
{"id":1}
|
||||
{"id":2}
|
||||
{"id":3}`},
|
||||
{
|
||||
name: "donatello-3",
|
||||
query: `SELECT * from s3object s WHERE 'value' IN s.synonyms[*]`,
|
||||
|
@ -355,7 +370,9 @@ func TestJSONQueries(t *testing.T) {
|
|||
|
||||
testReq := testCase.requestXML
|
||||
if len(testReq) == 0 {
|
||||
testReq = []byte(fmt.Sprintf(defRequest, testCase.query))
|
||||
var escaped bytes.Buffer
|
||||
xml.EscapeText(&escaped, []byte(testCase.query))
|
||||
testReq = []byte(fmt.Sprintf(defRequest, escaped.String()))
|
||||
}
|
||||
s3Select, err := NewS3Select(bytes.NewReader(testReq))
|
||||
if err != nil {
|
||||
|
@ -401,7 +418,9 @@ func TestJSONQueries(t *testing.T) {
|
|||
}
|
||||
testReq := testCase.requestXML
|
||||
if len(testReq) == 0 {
|
||||
testReq = []byte(fmt.Sprintf(defRequest, testCase.query))
|
||||
var escaped bytes.Buffer
|
||||
xml.EscapeText(&escaped, []byte(testCase.query))
|
||||
testReq = []byte(fmt.Sprintf(defRequest, escaped.String()))
|
||||
}
|
||||
s3Select, err := NewS3Select(bytes.NewReader(testReq))
|
||||
if err != nil {
|
||||
|
|
|
@ -309,7 +309,7 @@ func (v Value) CSVString() string {
|
|||
// floatToValue converts a float into int representation if needed.
|
||||
func floatToValue(f float64) *Value {
|
||||
intPart, fracPart := math.Modf(f)
|
||||
if fracPart == 0 {
|
||||
if fracPart == 0 && intPart < math.MaxInt64 && intPart > math.MinInt64 {
|
||||
return FromInt(int64(intPart))
|
||||
}
|
||||
return FromFloat(f)
|
||||
|
|
Loading…
Reference in New Issue