Skip to content

reject colwise csv map rows with more cells than columns - #2994

Merged
stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:csv-colwise-map-extra-cells
Oct 15, 2026
Merged

stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:csv-colwise-map-extra-cells

Conversation

@uwezkhan

@uwezkhan uwezkhan commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

The colwise reader for std::map<std::string, std::vector> (from<CSV, readable_map_t>::op in include/glaze/csv/read.hpp) advances its per-row loop only past a comma, CR, or LF once it has read n_keys cells, and never looks at ctx.error between fields. A data row carrying more cells than there are header columns, or a field the reader stopped on a stray byte, leaves the iterator on a byte neither the delimiter nor the newline branch consumes, so the outer while(it != end) loop makes no progress.

Before, a,b\n1,2,3\n into a string-valued map read as success with the third cell misassigned to a second row of column a and an empty inserted into b, and the same row of a numeric map set parse_number_failure that the loop dropped and then spun on, emplacing default elements. After, both are a syntax_error. The fix bails on ctx.error after each field and rejects a row not closed by a newline or end of input, which is what the sibling colwise struct reader and the rowwise readers already do; keeping the check in this loop is why the four readers now agree on what a row is. The tradeoff is that a row with trailing content past its columns is now refused rather than partially consumed; a well-formed document, including a last row with no trailing newline, is unchanged.

@stephenberry

Copy link
Copy Markdown
Owner

Thanks for the fix! I pushed a small cleanup: the row ending now uses csv_new_line, matching the struct colwise reader, and the numeric extra-cell test checks for syntax_error.

@stephenberry
stephenberry merged commit 9f6b386 into stephenberry:main Oct 15, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants