-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Fix reply bytes calculation error on 32bit platform #7299
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
Conversation
|
Thank you @ShooterIT, I'll release a new Redis 6 version with this fix ASAP. |
|
sorry about that. (second embarrassing bug in that simple function). the lesson learned here (which is similar to the one i learned from the last fuckup in that function), is that our CI lucks coverage for 32bit builds (previous time was libc allocator). for the record, i think the cleaner fix to keep using |
|
@oranagra NP, bugs happen. Agreed with the CI. About the different fix, I kinda disagree because I think in this specific case, it is cleaner to avoid that at any given point we compute a negative value. With the proposed fix, when we do value = value + a - b, given that we are sure (value+a) itself will not overflow since it's 64 bits, and even so it's unsigned, so defined semantics, then we remove b and we are set. Your proposed fix works as well, but it is kinda counter intuitive that we compute a negative increment to start with, and then add it to our value. Here I assume that (a-b) is always <= 0. |
|
well, maybe it's a matter of taste (i preferred to see a delta which i knew may be negative, and then add it). anyway, i didn't mean we should add another commit, the one we have fixes the bug and that's enough, just wanted to comment. i'll add CI for 32bit sometime next week. |
|
@oranagra thanks, btw I think the current fix would be better if there was a comment about that. |
|
Anyway you know what's fun? That I always thought that actually even if unsigned integers overflow are well defined in C, signed math is much more safe in general. This is a good example. I'll never understand why the ANSI C standard is so terrible about not well-defining signed math in C. It would be straight forward and what 99.99% of the widely used CPUs already do. They are handling C terribly IMHO :-( |
|
Hi @oranagra Adding CI for 32bit is definitely necessary. For my PR #7090 , I don't want to use temporary variable |
|
Hello @antirez For 64bit, the previous code result is correct yet, because it overflows twice. Just like you said, unsigned integers overflow are well defined in C, but that may hide errors logically. |
|
CI for 32bit: #7315 |
Fix reply bytes calculation error on 32bit platform

Fix #7275.
For this line https://github.com/antirez/redis/blob/unstable/src/networking.c#L491
On 32bit platform, the type of
c->reply_bytesis unsigned long long, so it is 8 bytes,the types of
tail->sizeandold_sizeare size_t, so it is 4 bytes,old_sizeis exactly bigger thattail->size, so the result oftail->size - old_sizeis very big.But
c->reply_bytesis 8 bytes, the result will be add at last 4 bytes inc->reply_bytes, soc->reply_bytesis very big. Redis will coredump when executeserverAssert(c->reply_bytes < SIZE_MAX-(1024*64));BTW, for current unstable branch, tests will exit with errors if we
make 32bitandsh runtest.There is a test, output is
4294967395.@antirez @oranagra