Repository navigation
fix(autoindex): cap CSV record size so one quoted field cannot allocate the whole file - #3202
Conversation
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
|
ES-YAML conformance gate, run locally after the PR opened: 1448 passed, 0 failed, 10 skipped, 1458 total, exit 0. Command: started the release binary from this head with a fresh data dir, then cargo run --release -p es-yaml-runner -- --dir tests/es-compat-yaml/yaml. The PR body said the gate was not run locally; that is now out of date, the gate is green on this head. |
|
Thanks @Varshith-Kali, I reviewed this and it looks correct: the shared |
05ca0ad to
aac39bb
Compare
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
|
Thanks, glad the shared RecordByteCap and the at-cap and over-cap behaviour read right. The CLA line and a green CI run are still the open items, with CI approved but still queued. Also rebased onto current main, no code changes in the rebase. |
aac39bb to
5b9a9d6
Compare
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
|
Rebased onto main dc1a462. The only conflict was CHANGELOG.md, both entries kept. No code change from the tested head. |
drk-ram
left a comment
There was a problem hiding this comment.
Reviewed engine/crates/xerj-autoindex/src/extract/csv_x.rs and mod.rs (5b9a9d63):
- Streaming per-record byte cap (
RecordByteCap/MAX_CSV_RECORD_BYTES = 16 MiB): Enforcing the 16 MiB cap inside the underlyingReadwrapper (open_reader_with_cap) stops thecsvparser before an unclosed quote can buffer a multi-gigabyte file into a single field, and resetting the counter after each valid header/record while treating a tripped header/record asstats.junk += 1ensures one hostile CSV file cannot abort an entire autoindex run (#3201).
5b9a9d6 to
43d39d4
Compare
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
…te the whole file Motivation: the CSV extractor reads records through csv::ReaderBuilder with no per-record size cap, while a quoted field may span newlines. One hostile file with a single giant quoted field makes the parser buffer the whole input before returning the first record, then each field is copied into a String and a JSON map, so the bytes are held several times over. The module header at extract/mod.rs claims every extractor is bounded-memory; CSV was the exception (issue xerj-org#3201). Root cause: the Rust csv crate (v1) offers no record or field size option on ReaderBuilder, and open_reader only caps total bytes when a sampling limit is passed, while the index path calls extract with None, meaning the full stream. Gzip input is decoded with no cap on decompressed bytes. So nothing between the file and the record allocation bounded one record. Fix: a 16 MiB per-record cap (MAX_CSV_RECORD_BYTES), the same per-unit convention as MAX_LINE for JSONL and the YAML whole-file cap. A RecordByteCap shared between the reader and the extractor counts decoded bytes consumed since the last completed record and errors past the cap, before the parser can grow further. An oversize data record is counted as junk and extraction stops there, because the parser is mid-record inside the oversize field and cannot resume; the records before it still extract. An oversize header row junks the file instead of failing it, because an extract error aborts the whole autoindex run unless the file changed mid-run. A record 1 MiB under the cap still extracts unchanged. The reference is Python's csv module, which has enforced a per-field limit since 2003 (Modules/_csv.c, parse_add_char: field larger than field limit), because an unmatched quote could otherwise read the entire file into the field buffer; the Rust crate has no equivalent, so the bound lives in the reader instead. CHANGELOG entry added under [Unreleased]. Evidence: three new regression tests in csv_x.rs. The oversize-record and oversize-header tests were watched fail on unmodified main (3 records extracted instead of 1; header row extracted instead of junk) and pass with the fix. Full crate lib suite: 2048 passed, 1 failed (walk_only_summarises_without_opening_file_contents, verified failing on clean main too, a pre-existing sandbox failure; walk.rs does not use open_reader). csv_x tests: 13 passed. cargo fmt --all clean. cargo clippy -p xerj-autoindex: no warnings in the touched files; pre-existing warnings elsewhere (unused rustls workspace dep, chunks_exact in xerj-common, fetch_update deprecation in lib.rs) left untouched. Scoped release build cargo build --release -j 32 -p xerj-autoindex: green in 2m16s. ES-YAML gate: not run locally yet, see the PR body. Written by an AI coding agent (Muse), run by Varshith-Kali, who has reviewed this change.
43d39d4 to
063296e
Compare
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
Written by an AI coding agent (Muse), run by @Varshith-Kali, who has reviewed this change.
Fixes #3201.
Motivation: the CSV extractor reads records through csv::ReaderBuilder with no per-record size cap, while a quoted field may span newlines. One hostile file with a single giant quoted field makes the parser buffer the whole input before returning the first record, then each field is copied into a String and a JSON map, so the bytes are held several times over. The module header at extract/mod.rs claims every extractor is bounded-memory; CSV was the exception.
Root cause: the Rust csv crate (v1) offers no record or field size option on ReaderBuilder, and open_reader only caps total bytes when a sampling limit is passed, while the index path calls extract with None, meaning the full stream. Gzip input is decoded with no cap on decompressed bytes.
Fix: a 16 MiB per-record cap (MAX_CSV_RECORD_BYTES), the same per-unit convention as MAX_LINE for JSONL and the YAML whole-file cap. A RecordByteCap shared between the reader and the extractor counts decoded bytes consumed since the last completed record and errors past the cap, before the parser can grow further. An oversize data record is counted as junk and extraction stops there, because the parser is mid-record inside the oversize field and cannot resume; the records before it still extract. An oversize header row junks the file instead of failing it, because an extract error aborts the whole autoindex run unless the file changed mid-run. A record 1 MiB under the cap still extracts unchanged. CHANGELOG entry added under [Unreleased].
Reference: the Python csv module has enforced a per-field limit since 2003 (Modules/_csv.c, parse_add_char: field larger than field limit), because an unmatched quote could otherwise read the entire file into the field buffer. The Rust crate has no equivalent, so the bound lives in the reader instead. Approach only, nothing copied.
Verified, commands run in this environment, output observed:
Assumed, NOT tested:
Not run: the ES-YAML conformance gate. It needs a full-server release binary plus a live node running 1454 cases, and this change touches only the CSV extractor read path (no query, mapping, index, or wire code). CI covers it.
CLA: the CLA signature is for Varshith Puli personally and is not signed here; the verification/cla-signed check will need his signature.