Repository navigation
Fix reading past the buffer after an escape sequence in TSV with input_format_tsv_crlf_end_of_line - #123861
Conversation
… line endings With `input_format_tsv_crlf_end_of_line = 1`, `readEscapedStringIntoImpl` checked for '\r' right after handling an escape sequence, without checking that the buffer still had data. When the escape sequence ended exactly at the end of the working buffer, it read the byte past the end. That byte is inside the buffer padding, so ASan does not see it, but MSan reports it as uninitialized (BuzzHouse amd_msan, STID 2798-4afa, via `url()` and `ReadBufferFromIStream`). If the stale byte was '\r', the position moved past the end of the buffer: debug builds abort on `pos_addr <= end_addr`, release builds throw `std::length_error` or segfault. The CR branch is only meant for the '\r' found by `find_first_symbols`, so it is now the `else` of the escape branch. After an escape sequence the loop goes back to `while (!buf.eof())`, which refills the buffer, and a following '\r' is found by the next `find_first_symbols` and handled by the same branch, so the result is unchanged for every input that does not hit the boundary. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261004-132200 |
|
Workflow [PR], commit [eb93d46] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ No findings. The fix matches the stated bug, the test covers the affected paths, prior discussion does not leave an unresolved issue, and CI is all green. LLVM Coverage ReportMeasured on commit eb93d46.
Changed lines: Changed C/C++ lines covered: 1/1 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
|
The sync PR failure is unrelated |
961b4f7
Backport #123861 to 26.9: Fix reading past the buffer after an escape sequence in TSV with input_format_tsv_crlf_end_of_line
Backport #123861 to 26.8: Fix reading past the buffer after an escape sequence in TSV with input_format_tsv_crlf_end_of_line
Backport #123861 to 26.3: Fix reading past the buffer after an escape sequence in TSV with input_format_tsv_crlf_end_of_line
Backport #123861 to 26.7: Fix reading past the buffer after an escape sequence in TSV with input_format_tsv_crlf_end_of_line
… an escape sequence in TSV with input_format_tsv_crlf_end_of_line
… an escape sequence in TSV with input_format_tsv_crlf_end_of_line
… an escape sequence in TSV with input_format_tsv_crlf_end_of_line
… an escape sequence in TSV with input_format_tsv_crlf_end_of_line
Related: #119168
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a segmentation fault or
std::length_errorwhen readingTSVformats withinput_format_tsv_crlf_end_of_line = 1if an escape sequence ended exactly at the end of a read buffer.Description
On 26.9 and 26.8,
SELECT * FROM file('data.tsv', 'TSVWithNames', 's String')withinput_format_tsv_crlf_end_of_line = 1segfaults when a field's escape sequence ends exactly at the end of a read buffer and the next byte in memory is\r; on 26.3 and 25.3 the same query fails withstd::length_error. The same over-read is theMemorySanitizer: use-of-uninitialized-valueinreadEscapedStringIntoImplfound by BuzzHouse (amd_msan): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119168&sha=39d344b70a3cd3857d754e8b16832e4ddbdb802f&name_0=PR&name_1=BuzzHouse%20%28amd_msan%29readEscapedStringIntoImplchecked for\rright after an escape sequence without checking that the buffer still had data, so it read the byte after the working buffer (inside the padding, so ASan is silent, and uninitialized for MSan). A stale\rthere moved the position past the end of the buffer, and the next append got a negative length.ReadBufferFromIStreamand the HTTP buffer from the report are not at fault:file()hits the same path.The
\rcheck is now theelseof the escape branch, so it only sees a\rfound byfind_first_symbols. After an escape sequence the loop refills the buffer and a following\rtakes the same branch, so the result is unchanged for every input away from the boundary.The test reads an 18-byte file with
max_read_buffer_size = 16, so the second read holds only\tand the next byte is a stale\r. Without the fix each of its three queries (header, data row, schema inference) aborts a debug build withLogical error: 'pos_addr <= end_addr'.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123861]
Version info
26.10.1.1569-master(included in26.10and later)26.9.11.2,26.8.18.3,26.7.22.7,26.3.42.4