Repository navigation
Fix use-of-uninitialized-value in parseDateTimeBestEffort - #61694
Merged
Merged
Conversation
Contributor
|
This is an automated comment for commit f162ea8 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
vdimir
approved these changes
Mar 21, 2024
alexey-milovidov
approved these changes
Mar 21, 2024
lneves12
pushed a commit
to lneves12/ClickHouse
that referenced
this pull request
Oct 5, 2026
parseDateTimeBestEffortImpl dereferences in.position() in the num_digits == 0 branch with no eof() check. The enclosing while (!in.eof()) loop only guarantees a readable byte at the top of an iteration, and the alphabetical-month branch both leaves num_digits == 0 and can consume the last byte of the value, so a value such as '1-Jan' reaches that read with the position already at the end of the buffer. Since 0bd3c24 ("Remove zero byte", ClickHouse#85063) ColumnString no longer stores a trailing terminator, so getDataAt() returns a span ending exactly at the value. The byte read is therefore the first byte of the next row, or the uninitialized right padding of the chars array when the value is the last row. When that byte is one of ' ', 'Z', '.', '+' or '-', the code advances the position past working_buffer.end(); BufferBase::available() is an unclamped size_t(end - pos), so it wraps, eof() never becomes true again, and the parser keeps consuming the neighbouring rows. The consequence differs by caller. The conversion family re-checks isAllRead(), so parseDateTimeBestEffort*, parseDateTime64BestEffort* and toDateTime with date_time_input_format = 'best_effort' reject a valid value (NULL, zero, or CANNOT_PARSE_TEXT). addMonths and the rest of the add-interval family over a String argument do not re-check, so they return date and time fields taken from the following row. Guarding the read with eof() restores the control flow the terminator used to produce: '\0' fell through to readAlpha, which returned zero characters and broke out of the loop. eof() attempts a refill first, so a value straddling a chunk boundary in a refillable ReadBuffer keeps parsing; a plain pointer comparison would have stopped early there. Reported by the memory sanitizer as use-of-uninitialized-value src/IO/parseDateTimeBestEffort.cpp:703:26 in Unit tests (msan, function_prop_fuzzer) on PR ClickHouse#116042 (914a539) and PR ClickHouse#118721 (906e40f), and at the same column in 2024 as issue ClickHouse#61771. PR ClickHouse#61694 added this same guard to the comma branch of this loop; the num_digits == 0 branch was not part of that change. Related: ClickHouse#61771
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Report: link