* [PATCH 1/2] fincore: Handle large files correctly on 32 bit
@ 2018-02-25 19:27 Tobias Stoeckmann
2018-02-26 10:56 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Stoeckmann @ 2018-02-25 19:27 UTC (permalink / raw)
To: util-linux
If a file is larger than 4 GB on a 32 bit system with large file
support (default), it can happen that not all pages are properly
processed. This happens due to an int truncation (off_t vs size_t).
You can reproduce this on 32 bit with these commands:
$ dd if=/dev/zero of=4gb-file seek=4294967295 count=1 bs=1
$ fincore 4gb-file
fincore: failed to do mmap: 4gb-file: Invalid argument
If a file is larger than 4 GB, the first few pages of a file won't
be properly processed. "len" will be smaller than window_size,
but the for-loop iterates "window_size" bytes, skipping some pages.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
misc-utils/fincore.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c
index 4641408f8..ab11594cc 100644
--- a/misc-utils/fincore.c
+++ b/misc-utils/fincore.c
@@ -199,11 +199,11 @@ static int fincore_fd (struct fincore_control *ctl,
int warned_once = 0;
for (file_offset = 0; file_offset < file_size; file_offset += window_size) {
- size_t len;
+ off_t len;
void *window = NULL;
len = file_size - file_offset;
- if (len >= window_size)
+ if (len >= (off_t) window_size)
len = window_size;
window = mmap(window, len, PROT_NONE, MAP_PRIVATE, fd, file_offset);
--
2.16.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-26 10:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-25 19:27 [PATCH 1/2] fincore: Handle large files correctly on 32 bit Tobias Stoeckmann
2018-02-26 10:56 ` Karel Zak
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.