All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: util-linux@vger.kernel.org
Subject: [PATCH 2/2] fincore: Handle large files on 32 bit without LFS
Date: Sun, 25 Feb 2018 20:27:59 +0100	[thread overview]
Message-ID: <20180225192758.GB5871@localhost> (raw)

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.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
 misc-utils/fincore.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c
index ab11594cc..f9534e85b 100644
--- a/misc-utils/fincore.c
+++ b/misc-utils/fincore.c
@@ -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;
-- 
2.16.2


             reply	other threads:[~2018-02-25 19:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-25 19:27 Tobias Stoeckmann [this message]
2018-02-26 10:56 ` [PATCH 2/2] fincore: Handle large files on 32 bit without LFS Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180225192758.GB5871@localhost \
    --to=tobias@stoeckmann.org \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.