-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[win64] fix for broken hash fn on windows 64: ensure modulo performed on unsigned ints. #712
Conversation
Thanks. Curious though why this hasn't caused any problems until now. Most 64bit systems have 64 bit size_t and 32 bit ints so why does it happen to you at this time and on win64 only, do you know? |
The type cast change should indeed be fine. For consistency, I'll also change the typecast in the |
Oh. It really should use a |
So my suggested edit would make the patch like this:
|
… on curl_socket_t (unsigned).
@bagder we've had this not working on 64-bit windows for a while, but figured it'd be fixed upstream. I just think the problem had largely gone unnoticed by the community, for us it seems like the problem arises strictly when using curl multi. I feel like It might be a compiler issue on I think the case that triggers the segfault is when I submitted an amended version. Let me know if you want me to make any additional changes, or touch-up anything else. |
I take you tested your original case with this amended version? It looks fine to me. About storing |
Oh, and I don't think it actually stores CURL_SOCKET_BAD in the hash, I think it looks for it when it asks for a hash for that socket value. |
Simplify the code by using a single entry that looks for a socket in the socket hash. As indicated in #712, the code looked for CURL_SOCKET_BAD at some point and that is ineffective/wrong and this makes it easier to avoid that.
@bagder I can confirm the fixed hash function addresses the issue described originally in pycurl/pycurl#395 I can see you closed the PR, do you handle these patches separately? Thanks a lot! |
It was closed when the commit was merged into the curl repository. I also did a follow-up fix then to make sure we don't store in invalid sockets in the hash. |
Awesome! Thanks a lot @bagder |
@truthbk now i was use win10 64bit, how to fix this issue ? |
I'm sorry @sbmzhcn I didn't see this last summer. You should be good just using libcurl 7.48.0 or greater, this fix was included there. |
As discussed here: pycurl/pycurl#395 there is an issue on 64 bit windows that will produce a segmentation fault due to bad indexing on the hash table due to a broken hash function
hash_fd():lib/multi.c:237
that would operate over a negative value as a product of casting toint
. The negative value result of the function, when returned assize_t
represents a very large number, that causes a segfault when indexing the hash table.Because it's just a hash function, the impact of performing the hash function over a cast to
unsigned int
s should be none, and would incur in no performance penalty. Alternatively I can provide a fix that would ensure we always operate on positive via bitwise operations that would consume three additional cpu cycles. Let me know what's preferable.