-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
[CHUNKCOPY_SAFE] Fix off-by-one error #982
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #982 +/- ##
===========================================
- Coverage 76.42% 76.32% -0.10%
===========================================
Files 74 74
Lines 8305 8313 +8
Branches 1369 1370 +1
===========================================
- Hits 6347 6345 -2
- Misses 1427 1439 +12
+ Partials 531 529 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
b10175f
to
0316dd6
Compare
It does not fix #979. I'm not sure I understand the off-by-one error. |
@nmoinvaz I think there might be error in code calling |
I don't think there is any off by one issue. Having the I haven't tested it very well. It always makes sure that What do you think? |
I was thinking of adding
to top of |
@mtl1979 are you able to make the |
@nmoinvaz I don't think separating the move of MIN() is hard... |
b11e14f
to
75288eb
Compare
Rebased. |
I still don't understand why it is off by one. |
If you have buffer of 31 bytes, it is indexed from 0 to 30... That is where the Safe length can calculated by formula 30 (end index) - 0 (start index) + 1 = 31. In this case it comes to the comparison, which is |
Please rebase, so we get the new CI-tests too :) |
Benchmarks should be done as well. |
On my benchmark, difference between unrolling and not unrolling in chunkmemset_safe() was 23 ms using 211957760 bytes long file. |
I think this "off-by-one" bug should be its own PR with 1 commit and anything else should be a separate 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.
Maybe... I just wanted to keep them together to test for any side-effects... If I separate, the "remaining" part must be merged in before the "off-by-one" fix. Then I can just rebase over for a really clean diff. |
* When chunk size was more than 8 bytes, the comparison logic failed if safe length was one less than chunk size.
…to avoid errors with optimizations enabled.
* limit len to minimum of len and left
LGTM, but I am not so steady on the intricacies of the chunkset code, so I have not verified its correctness but rather its scope. |
@Dead2 From the start nobody was really sure about correctness of the chunkset code, they just assumed it was correct because it didn't crash or fail any CI tests back then... After adding pigz test, this is the first pull request that doesn't fail it and does not introduce new failures either. Codecov test fails only because this pull request replaces direct calls to two functions with indirect calls through another set of two functions. It's really hard to spot off-by-one errors in any code and even more when there is guard bytes added by user application instead of the C library. |
Baseline 5cfb7f1
PR #982 eb212936dd6da4222f566ea82f8ad48665aa614c
|
- Fix inflate corruption #982 - Minor code cleanup #983 #984 - Fix mpicc compilation #959 - Fix build on NetBSD #964 - Fix build on OpenBSD #970 - Fix build on Cygwin #972 #974 - Fix linter warnings in configure #975 - Spelling fixes #961 - Improve unistd.h handling #960 - Remove stdarg.h detection #976 - CI/Test improvements #977 #981 #985 - Cmake improvements #980 #989
- Fix inflate corruption #982 - Minor code cleanup #983 #984 - Fix mpicc compilation #959 - Fix build on NetBSD #964 - Fix build on OpenBSD #970 - Fix build on Cygwin #972 #974 - Fix linter warnings in configure #975 - Spelling fixes #961 - Improve unistd.h handling #960 - Remove stdarg.h detection #976 - CI/Test improvements #977 #981 #985 - Cmake improvements #980 #989
I am getting some warnings now on MSVC:
|
@nmoinvaz That's because I didn't change the function signatures to use |
Casting the pointer difference to |
How is it allowed to be -1? |
@nmoinvaz Because |
len
is less than remaining buffer length,CHUNKCOPY_SAFE
now uses smaller chunks to avoid writing past of end of buffer.