Skip to contentSkip to conversation

fincore: Handle large files on 32 bit without LFS

PATCH Applied Tobias Stoeckmann 2 participants 2 messages Feb 25, 2018 – Feb 26, 2018 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 fincore: Handle large files on 32 bit without LFS

If util-linux is installed on a system without large file support, an out of memory issue can occur while processing a file which is 2 GB in size:

$ ./configure --disable-largefile && make
$ dd if=/dev/zero of=2gb-file seek=2147483646 count=1 bs=1
$ fincore 2gb-file
(endless loop)
fincore: failed to do mmap: 2gb-file: Cannot allocate memory

Even though iterating with "len" seems counter-intuitive, it fixes this issue. The variable len is only in the last iteration not a multiplication of pagesize -- which is the requirement for mmap.

---
 misc-utils/fincore.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
misc-utils/fincore.c +2 -3
index ab11594cc..f9534e85b 100644
@@ -194,12 +194,11 @@ static int fincore_fd (struct fincore_control *ctl,
 		       off_t *count_incore)
 {
 	size_t window_size = N_PAGES_IN_WINDOW * ctl->pagesize;
-	off_t file_offset;
+	off_t file_offset, len;
 	int rc = 0;
 	int warned_once = 0;
 
-	for (file_offset = 0; file_offset < file_size; file_offset += window_size) {
-		off_t len;
+	for (file_offset = 0; file_offset < file_size; file_offset += len) {
 		void  *window = NULL;
 
 		len = file_size - file_offset;
Signature · 1 line
2.16.2
maintainer Applied
#1 lore raw
Quoted 2 lines · Tobias Stoeckmann
 misc-utils/fincore.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com