From 1c0b471cac16ae032e385b3ae4bb1c8a91b80c2b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 29 Dec 2022 10:33:17 -0800 Subject: [PATCH] vendor: update github.com/valyala/fastjson/fastfloat from v1.6.3 to v1.6.4 This should properly parse floating-point numbers with missing integer or fractional parts. For example, 123. or .123 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3544 --- docs/CHANGELOG.md | 1 + go.mod | 2 +- go.sum | 4 ++-- .../valyala/fastjson/fastfloat/parse.go | 24 +++++++++++++++---- vendor/modules.txt | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8d1c9a24a..64d021e35 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,7 @@ The following tip changes can be tested by building VictoriaMetrics components f ## v1.79.x long-time support release (LTS) +* BUGFIX: properly parse floating-point numbers without integer or fractional parts such as `.123` and `20.` during [data import](https://docs.victoriametrics.com/#how-to-import-time-series-data). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3544). * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly parse durations with uppercase suffixes such as `10S`, `5MS`, `1W`, etc. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3589). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): [dockerswarm_sd_configs](https://docs.victoriametrics.com/sd_configs.html#dockerswarm_sd_configs): properly encode `filters` field. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3579) * BUGFIX: allow specifying values bigger than 2GiB to the following command-line flag values on 32-bit architectures (`386` and `arm`): `-storage.minFreeDiskSpaceBytes` and `-remoteWrite.maxDiskUsagePerURL`. Previously values bigger than 2GiB were incorrectly truncated on these architectures. diff --git a/go.mod b/go.mod index 21f8af118..554e6bca4 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/klauspost/compress v1.15.12 github.com/prometheus/prometheus v1.8.2-0.20201119142752-3ad25a6dc3d9 github.com/urfave/cli/v2 v2.23.7 - github.com/valyala/fastjson v1.6.3 + github.com/valyala/fastjson v1.6.4 github.com/valyala/fastrand v1.1.0 github.com/valyala/fasttemplate v1.2.2 github.com/valyala/gozstd v1.17.0 diff --git a/go.sum b/go.sum index 80277207b..e2213a02d 100644 --- a/go.sum +++ b/go.sum @@ -773,8 +773,8 @@ github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6f github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= -github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= -github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= +github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= +github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= diff --git a/vendor/github.com/valyala/fastjson/fastfloat/parse.go b/vendor/github.com/valyala/fastjson/fastfloat/parse.go index 5d4a7c7a7..b37838da6 100644 --- a/vendor/github.com/valyala/fastjson/fastfloat/parse.go +++ b/vendor/github.com/valyala/fastjson/fastfloat/parse.go @@ -213,6 +213,12 @@ func ParseBestEffort(s string) float64 { } } + // the integer part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + if s[i] == '.' && (i+1 >= uint(len(s)) || s[i+1] < '0' || s[i+1] > '9') { + return 0 + } + d := uint64(0) j := i for i < uint(len(s)) { @@ -232,7 +238,7 @@ func ParseBestEffort(s string) float64 { } break } - if i <= j { + if i <= j && s[i] != '.' { s = s[i:] if strings.HasPrefix(s, "+") { s = s[1:] @@ -263,7 +269,9 @@ func ParseBestEffort(s string) float64 { // Parse fractional part. i++ if i >= uint(len(s)) { - return 0 + // the fractional part may be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + return f } k := i for i < uint(len(s)) { @@ -363,6 +371,12 @@ func Parse(s string) (float64, error) { } } + // the integer part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + if s[i] == '.' && (i+1 >= uint(len(s)) || s[i+1] < '0' || s[i+1] > '9') { + return 0, fmt.Errorf("missing integer and fractional part in %q", s) + } + d := uint64(0) j := i for i < uint(len(s)) { @@ -382,7 +396,7 @@ func Parse(s string) (float64, error) { } break } - if i <= j { + if i <= j && s[i] != '.' { ss := s[i:] if strings.HasPrefix(ss, "+") { ss = ss[1:] @@ -413,7 +427,9 @@ func Parse(s string) (float64, error) { // Parse fractional part. i++ if i >= uint(len(s)) { - return 0, fmt.Errorf("cannot parse fractional part in %q", s) + // the fractional part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + return f, nil } k := i for i < uint(len(s)) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 3f6633472..e2c3603d0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -236,7 +236,7 @@ github.com/urfave/cli/v2 # github.com/valyala/bytebufferpool v1.0.0 ## explicit github.com/valyala/bytebufferpool -# github.com/valyala/fastjson v1.6.3 +# github.com/valyala/fastjson v1.6.4 ## explicit; go 1.12 github.com/valyala/fastjson github.com/valyala/fastjson/fastfloat