time: fix TimeFormatter returning nil for the Unix epoch (#5420)
Which issue(s) this PR fixes: Fixes #
What this PR does / why we need it:
TimeFormattercaches the last two formatted timestamps in two slots, and an empty slot was marked by its key being0. But0is a valid timestamp, so the epoch matched an empty slot and itsnilstring was returned as a cache hit:Fluent::TimeFormatter.new(nil, false, nil).format(0) #=> nil
format_with_subseccompares slots withEventTime.eq?, which falls back toEventTime#==and compares seconds alone, so there the whole first second of the epoch is affected:fmt = Fluent::TimeFormatter.new("%Y%m%d %H%M%S.%N", false, nil) fmt.format(Fluent::EventTime.new(0, 123456789)) #=> nilThe fix is to mark an empty slot by its cached string being
nilrather than by its key.format_nocachealways returns aString, so a filled slot can never be mistaken for an empty one. Every other timestamp behaves exactly as before, since key0could never have matched it.Impact is small, and I don’t think this is urgent. A slot keeps the key
0only until it is written, so a formatter self-heals once it has formatted two distinct timestamps, within a second of the first record. The exception is a stream whose timestamps are all the epoch: the early return never fills a slot, andout_filethen writes every line with an empty time column. That is reachable viatime_type unixtime, which parses withvalue.to_iand turns an empty or non-numerictime_keyintoEventTime.new(0), but such a pipeline is misconfigured anyway. The reason to fix it is simply thatnilis never a correct result.Docs Changes:
Release Note:
- time: fix TimeFormatter returning nil for the Unix epoch
Signed-off-by: Shizuo Fujita fujita@clear-code.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Fluentd: Open-Source Log Collector
Fluentd collects events from various data sources and writes them to files, RDBMS, NoSQL, IaaS, SaaS, Hadoop and so on. Fluentd helps you unify your logging infrastructure (Learn more about the Unified Logging Layer).
Quick Start
Development
Branch
Prerequisites
gitshould be inPATH. On Windows, you can useGithub for WindowsandGitShellfor easy setup.Install dependent gems
Use bundler:
Run test
You can run specified test via
TESTenvironment variable:More Information
Security
A third party security audit was performed by Cure53, you can see the full report here.
See SECURITY to contact us about vulnerability.
Contributors:
Patches contributed by great developers.