ensure copy of p when Writing stays within bounds#3
ensure copy of p when Writing stays within bounds#3djherbis merged 1 commit intodjherbis:masterfrom danp:ensure-bounds
Conversation
|
Very nice catch, you're right that gap could grow beyond the size of p after a wait! I think I have a few comments to make, but this is def. a good fix thanks! |
| } | ||
|
|
||
| // chunk write to fill space | ||
| m, err = w.b.Write(p[n : int64(n)+gap(w.b)]) |
There was a problem hiding this comment.
Why don't we break out this inner for loop if gap(w.b) >= int64(len(p[n:]), it'll then fall through to just do a std. write, and the write should fit entirely in the buffer (we won't lose/regain the lock again).
There was a problem hiding this comment.
Also, do you mind re-basing (I only modified the travis file) so that travis will run correctly?
(not sure why my travis script broke over time)
There was a problem hiding this comment.
Updated, does it look like what you were thinking? Seems to still pass my test.
There was a problem hiding this comment.
Looks good, merged it in and included it in release v2.0.1.
I'll probably try and add some more tests to hit this case/boost coverage. It's hard to test toctou conditions reliably. Kicking myself that I missed this, but thankful you caught it!
|
Wow that was blazing fast! Thank you very much for the fix :) I hope you're enjoying the library overall, sorry that it had a bug! |
I believe calling gap can race which can cause trying to access beyond the end of p. This came about via oklog/oklog#16.
With this patch I can run my test setup indefinitely. I also had debugging inside the if body which showed this at work: