Skip to content

Commit 77adcad

Browse files
authored
Merge pull request #8968 from dkorpel/csv-index-error
Fix bugzilla 24478 - std.csv array out of bounds when row size exceed…
2 parents 8729740 + 08b6dd3 commit 77adcad

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

std/csv.d

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ class CSVException : Exception
175175
assert(ex.toString == "(Row: 1, Col: 2) Unexpected 'b' when converting from type string to type int");
176176
}
177177

178+
// https://issues.dlang.org/show_bug.cgi?id=24478
179+
@safe unittest
180+
{
181+
import std.exception : collectException;
182+
import std.algorithm.searching : count;
183+
string text = "A, B\n1, 2, 3";
184+
auto ex = collectException!CSVException(csvReader!(string[string])(text, null).count);
185+
assert(ex.toString == "(Row: 1, Col: 3) row contains more values than header");
186+
}
187+
178188
@safe pure unittest
179189
{
180190
import std.string;
@@ -1179,7 +1189,10 @@ public:
11791189
{
11801190
for (; !recordRange.empty; recordRange.popFront())
11811191
{
1182-
aa[header[_input.col-1]] = recordRange.front;
1192+
const i = _input.col - 1;
1193+
if (i >= header.length)
1194+
throw new CSVException("row contains more values than header", _input.row, _input.col);
1195+
aa[header[i]] = recordRange.front;
11831196
}
11841197
}
11851198
catch (ConvException e)

0 commit comments

Comments
 (0)