-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] for testing : Fix 4Gb limit for large files on Git for Windows #2179
base: main
Are you sure you want to change the base?
Changes from 1 commit
5b60f72
9c2f8de
5554ca1
f05d8a6
fc00458
a4b2bb5
fb1a906
2ea5193
4bf4bda
21d51c0
8891566
eeb79ff
a8e0ee7
a85708c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ static const char *zerr_to_string(int status) | |
#define ZLIB_BUF_MAX ((uInt) 1024 * 1024 * 1024) /* 1GB */ | ||
static inline uInt zlib_buf_cap(size_t len) | ||
{ | ||
return (ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : len; | ||
return ((size_t) ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : (uInt) len; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But Therefore I doubt that this hunk is really necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm against implicit conversions for implementation defined concerns. One of them has to be probably wrong 😉 One of then is an up cast and the other a down cast, and they are being compared to each other... Aside: for testing, 1.5Gb is better, as it crosses the thresholds quickly and not at boundaries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can be against that all you want, at the same time you will have to abide by Git's conventions. And those conventions seem to avoid quite hard any unnecessary explicit cast. For example, when And do not forget that cluttering your code with unnecessary casts (or for that matter, cluttering your PR with unnecessary hunks) makes it much, much harder to read. So no, this hunk needs to be dropped, sorry. |
||
} | ||
|
||
static void zlib_pre_call(git_zstream *s) | ||
|
@@ -116,7 +116,7 @@ int git_inflate(git_zstream *strm, int flush) | |
zlib_pre_call(strm); | ||
/* Never say Z_FINISH unless we are feeding everything */ | ||
status = inflate(&strm->z, | ||
(strm->z.avail_in != strm->avail_in) | ||
((size_t) strm->z.avail_in != strm->avail_in) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm. That looks dubious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another nasty implicit conversion issue. They are different sizes and one definitely has wraparound relative to the other (z.avail_in is only 32bit, but strm->avail_in is full 64bit) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show me an explicit example where GCC (or Clang or MSVC) produces incorrect code for a |
||
? 0 : flush); | ||
if (status == Z_MEM_ERROR) | ||
die("inflate: out of memory"); | ||
|
@@ -242,7 +242,7 @@ int git_deflate(git_zstream *strm, int flush) | |
|
||
/* Never say Z_FINISH unless we are feeding everything */ | ||
status = deflate(&strm->z, | ||
(strm->z.avail_in != strm->avail_in) | ||
((size_t) strm->z.avail_in != strm->avail_in) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I think this entire commit can go without breaking anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same - being explicit about implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, let's not clutter the diff with unnecessary (and distracting) churn. |
||
? 0 : flush); | ||
if (status == Z_MEM_ERROR) | ||
die("deflate: out of memory"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
len
is already of typesize_t
, this cast is superfluous. The only real difference this would make was ifhdrlen
was negative. Which cannot be the case becausexsnprintf()
is explicitly not allowed to return negative values.So I'd just drop this hunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume the type of len because it (git_deflate_bound) may be a macro, or a function, and it is then subject to the compile flags.
Also, one of my readings of the various 'standards' suggested that it is within the implementation defined definition to downcast oversize variables if one (of the computation) was the normal 'right' size (e.g. long).
The whole up/down cast cascade and dual default function templates thing made me pedantic/explicit!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can. Because we declared it ourselves, a couple lines above the shown diff context, as
size_t len
. So we can very much assume that its type issize_t
.Nope. Arithmetic expressions are always evaluated after upcasting narrower data types to larger ones. A compiler that downcasts is buggy.
You probably think about an example like this:
This is a bit tricky to understand, as the evaluation of the arithmetic expression
a + b
really upcasts theint
to along
(unless they already have the same bit size). Only after that is the result downcast in order to be assigned to the narrowerresult
.That example has little relationship to the code under discussion, though, except in the case where
git_deflate_bound()
is defined as a function whose second parameter is declared with a too-narrow datatype. In which case you simply cannot do anything about it, except replace the function by our custom macro (as you did in another patch in this PR).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about the upcast to long. But when long is meant to be the maximum arithmetic calculation, then size_t may be down cast (as per Microsoft's desire that 32 bit code stays unchanged on 64 bit machines, so only (arithmetically) address 32bit range, unless one specially changes to full pointer calculation. As I understand it it's a bit open ended (which standard is your go to reference document?)
It maybe that the commit message needs to be long to explain the ripple through consequences, or we make the code informative. Its one of those 'discursive' areas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can. It is declared as
size_t len;
. See here:git/http-push.c
Line 363 in a4b2bb5