Skip to content

Commit 236bc5c

Browse files
committed
Fail when nrow_limit exceeds SIZE_MAX
Otherwise truncation occurs silently, possibly setting the limit to something like 100.
1 parent 0c6eff5 commit 236bc5c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/freadR.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ SEXP spillConnectionToFile(SEXP connection, SEXP tempfile_path, SEXP nrows_limit
833833

834834
const double nrows_max = REAL_RO(nrows_limit)[0];
835835
if (R_FINITE(nrows_max) && nrows_max >= 0.0) {
836+
if (nrows_max > SIZE_MAX)
837+
STOP(_("spillConnectionToFile: nrows_limit (%g) must fit into a native-size unsigned integer (<= %zu)"), nrows_max, (size_t)SIZE_MAX); // # nocov
836838
state.row_limit = (size_t)nrows_max;
837839
if (state.row_limit == 0) state.row_limit = 100; // read at least 100 rows if nrows==0
838840
state.row_limit++; // cater for potential header row

0 commit comments

Comments
 (0)