Re: [PATCH 13/14] git-compat-util.h: fix integer overflow on IL32P64 systems

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 13/14] git-compat-util.h: fix integer overflow on IL32P64 systems

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:02:40

Marat Radchenko [off-list ref] writes:
quoted hunk
Signed-off-by: Marat Radchenko <redacted>
---
 git-compat-util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index b338277..101c9d7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -474,7 +474,7 @@ extern int git_munmap(void *start, size_t length);
 #endif
 
 #define DEFAULT_PACKED_GIT_LIMIT \
-	((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
+	((size_t)(1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
1024 * 1024 * 8192 overflows 32-bit unsigned, but is size_t always
large enough?  Just checking.


-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Re: [PATCH 13/14] git-compat-util.h: fix integer overflow on IL32P64 systems

From: Johannes Schindelin <hidden>
Date: 2016-06-15 23:02:40

Hi Junio,

On Wed, 8 Oct 2014, Junio C Hamano wrote:
Marat Radchenko [off-list ref] writes:
quoted
 #define DEFAULT_PACKED_GIT_LIMIT \
-	((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
+	((size_t)(1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
1024 * 1024 * 8192 overflows 32-bit unsigned, but is size_t always
large enough?  Just checking.
The diff is a bit misleading as to what it *actually* changes. It *just*
casts the result to size_t. The arithmetic is performed with longs (thanks
to the "l" in 1024l) and it only overflows 32 bit iff the sizeof() test
verifies that we're at least on 64 bit -- this arithmetic operation is the
same as before the patch. I was fooled by the diff myself (adding another
parenthesis just to add the cast would probably have helped, though).

IMHO this is a good demonstration how a commit message that goes slightly
beyond the necessary can help tons of time by avoiding to let every
reviewer/reader go through the exact same steps of puzzlement.

Ciao,
Dscho

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help