From 51057cd1cb757ea7f4f06f28954e02adc5f73b6b Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Thu, 23 Oct 2025 20:16:41 +0200 Subject: [PATCH] add fix + NEWS --- NEWS.md | 2 ++ src/fread.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 60cb1dd0c..c7820d645 100644 --- a/NEWS.md +++ b/NEWS.md @@ -333,6 +333,8 @@ 19. Ellipsis elements like `..1` are correctly excluded when searching for variables in "up-a-level" syntax inside `[`, [#5460](https://github.com/Rdatatable/data.table/issues/5460). Thanks @ggrothendieck for the report and @MichaelChirico for the fix. +20. `fread()` now adds a small safety margin when reallocating for a reread after out-of-sample type bumps, so that healed rows when `fill=TRUE` cannot outrun the resized table, [#5110](https://github.com/Rdatatable/data.table/issues/5110). Thanks to @kmichelson for the report and @ben-schwen for the fix. + ### NOTES 1. The following in-progress deprecations have proceeded: diff --git a/src/fread.c b/src/fread.c index 1d43173b8..b1e9dab16 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2870,7 +2870,9 @@ int freadMain(freadMainArgs _args) size[j] = 0; } } - allocateDT(type, size, ncol, ncol - nStringCols - nNonStringCols, DTi); + // When type bump with fill occurs, reallocate with DTi (rows read so far) plus a buffer + // Using DTi alone could be short #5110 + allocateDT(type, size, ncol, ncol - nStringCols - nNonStringCols, DTi + (fill > 0 ? (DTi / 10) + 1 : 0)); // reread from the beginning DTi = 0; headPos = pos;