From 2bc1b3e4793d7d7d2ca7c275a51bb67d0d2a6035 Mon Sep 17 00:00:00 2001 From: Yorhel <git@yorhel.nl> Date: Thu, 22 Nov 2012 12:42:57 +0100 Subject: [PATCH] util.c: Fix possible buffer overflow in fillsize() and formatsize() They should now be able to cope with file sizes in the full (positive) range of a signed integer, i.e. 0 bytes to 8 EiB minus one byte. The size calculation of directories, however, may still overflow and cause negative integers to be passed around. That should be fixed. --- src/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 480e91b..d519581 100644 --- a/src/util.c +++ b/src/util.c @@ -62,15 +62,17 @@ char *formatsize(int64_t from) { else if(r < 1023e3f) { c = 'K'; r/=1024.0f; } else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; } else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; } - else { c = 'T'; r/=1099511627776.0f; } + else if(r < 1023e12f){ c = 'T'; r/=1099511627776.0f; } + else if(r < 1023e15f){ c = 'P'; r/=1125899906842624.0f; } + else { c = 'E'; r/=1152921504606846976.0f; } sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i'); return dat; } char *fullsize(int64_t from) { - static char dat[20]; /* max: 999.999.999.999.999 */ - char tmp[20]; + static char dat[26]; /* max: 9.223.372.036.854.775.807 (= 2^63-1) */ + char tmp[26]; int64_t n = from; int i, j; -- GitLab